Skip to content

Instantly share code, notes, and snippets.

@rahul8590
Created February 27, 2013 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahul8590/5048015 to your computer and use it in GitHub Desktop.
Save rahul8590/5048015 to your computer and use it in GitHub Desktop.
Have the function LetterCountI(str) take the str parameter being passed and return the first word with the greatest number of repeated letters. For example: "Today, is the greatest day ever!" should return greatest because it has 2 e's (and 2 t's) and it comes before ever which also has 2 e's. If there are no words with repeating letters return …
def LetterCountI(str):
l = []
index = 0
for k,i in enumerate(str.split(' ')):
d = {}
for j,c in enumerate(i):
d[c] = d.get(c,0) + 1
d = {key: value for key, value in d.items() if value != 1}
if (not l):
l.append(d)
else:
if len(l) > 0 and d:
if len(l[-1]) < len(d):
l.pop()
l.append(d)
index = k
if l[0]:
return str.split(' ')[index]
else:
return "-1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment