gList = ["A","A","C","C","B"] bucket = [] candy = {} list = [] x = 0 for g in gList: if g not in bucket: # go thru each item in gList. # When it sees an item not in bucket, it appends it to bucket. bucket.append(g) # bucket will only have one item from which to count repeated letters in gList. #.count() method returns count of how many times obj occurs in list. theCount = gList.count(bucket[0]) #print "theCount one", theCount # make the candy dictionary candy[str(bucket[0])]=theCount # delete it from list so it will start over. del bucket[0] a = candy[candy.keys()[x]] x = x + 1 print x b = candy[candy.keys()[x]] print "this is a", a print "this is b", b print x #if a == b: #print "YEEEES" print candy for k, v in candy.iteritems(): list.append(v) if v not in list: me = False else: me = True srt = sorted(candy.items(), key=lambda t: t[1]) theOne = len(srt) -1 theWinner = srt[theOne] print me if me == False: print "Its is a tie" else: print theWinner[0]
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question