Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Quick Lists Question (Count Occurences)
#11
If you can not use collections, write your own Counter:

def MyCounter(lst):
    dic = {}
    for e in lst:
        if e in dic:
            dic[e] += 1
        else:
            dic[e] = 1
    return dic

lst = []
print("Enter 9 numbers: ")
for i in range(9):
    lst.append(int(input()))

print(MyCounter(lst))
Quote
#12
(Nov-16-2016, 05:10 PM)nilamo Wrote:
(Nov-16-2016, 05:04 PM)metulburr Wrote: I thought you couldnt use collections?
That's not OP.

whoops lol 
LOL
Quote
#13
Thanks
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Count Letters in a Sentence (without using the Count Function) bhill 3 859 Jun-19-2018, 02:52 AM
Last Post: bhill
  regex, counting occurences yanhto 4 934 May-06-2018, 10:20 PM
Last Post: killerrex

Forum Jump:


Users browsing this thread: 1 Guest(s)