Counters in Python Simply Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ธ.ค. 2024

ความคิดเห็น •

  • @gangahitesh7885
    @gangahitesh7885 2 ปีที่แล้ว +8

    This guy is so underrated. Love your videos bro

  • @numberiforgot
    @numberiforgot 2 ปีที่แล้ว +1

    You do a really solid job explaining the different methods and what they do. A lot of university teachers aren’t even that proactive when they teach. I like how you explain each part of the code. This is quality content.

  • @lemonke8132
    @lemonke8132 2 ปีที่แล้ว +3

    why would you manually initialize a dictionary when you can use defaultdict(int)

  • @ilanbar1970
    @ilanbar1970 2 ปีที่แล้ว +1

    Big 👍 like. Always a pleasure to watch your posts

  • @andrewkraevskii
    @andrewkraevskii 2 ปีที่แล้ว

    I always used dictionary for counting. Find counter existence only last week and here is you video

  • @driedsquid3868
    @driedsquid3868 ปีที่แล้ว

    How would you count without using total()?

  • @Colaghiro
    @Colaghiro ปีที่แล้ว

    What programme are you using? My Python looks different. I'm so lost.

    • @UnbackedMuffn
      @UnbackedMuffn 11 หลายเดือนก่อน

      What text editor do you use? I think he might be using VS Code with a theme.

  • @arskiz
    @arskiz ปีที่แล้ว

    Bro, you sound like Tech With Tim :D

  • @ianbar20
    @ianbar20 ปีที่แล้ว

    The counter already orders elements by most occurrences to least. No need to use most_common

  • @gzbin365
    @gzbin365 2 ปีที่แล้ว

    nice video!

  • @jeffery_tang
    @jeffery_tang 2 ปีที่แล้ว

    This guy kind if looks like michael mando

  • @tcgvsocg1458
    @tcgvsocg1458 2 ปีที่แล้ว

    continue codewars /clash of code please

  • @ivegottaproblem
    @ivegottaproblem 2 ปีที่แล้ว

    First comment!!

  • @Press10
    @Press10 9 หลายเดือนก่อน

    I can't figure out what to type to get my last print result
    thislist = ["apple", "banana", "cherry"]
    x = input("Enter your item:")
    thislist.insert(1, (x))
    counter = Counter(thislist)
    print (counter.most_common()[0])
    message = input("Enter your item:")
    if message == counter.most_common()[0]:
    print("you win")

    • @ShashankSharma-ul5hi
      @ShashankSharma-ul5hi 3 หลายเดือนก่อน +1

      You need to changed your second last line. Why? Because counter.most_common()[0] is returning a tuple with the element and its count. If you entered apple it would be ('apple', 2). Now to get the 'apple' string from this tuple which is what your program seems to be checking you need to get the first element from that tuple which can be done like this.
      if message == counter.most_common()[0][0]: