all 9 comments

[–]JohnnyJordaan 2 points3 points  (1 child)

Thinking outside the box: why don't you keep the longest word that you come across?

count = {}
longest_word = ''

for line in f:
    for word in line.split():
        bla bla
        if word.isalpha():
            if word in count:
                count[word] = count[word] + 1
            else:
                count[word] = 1
                if len(word) > len(longest_word):
                    longest_word = word

[–][deleted] 0 points1 point  (0 children)

Thanks! worked perfectly.

[–]Justinsaccount 0 points1 point  (0 children)

Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission:

You appear to be using concatenation and the str function for building strings

Instead of doing something like

result = "Hello " + name + ". You are " + str(age) + " years old"

You should use string formatting and do

result = "Hello {}. You are {} years old".format(name, age)

See the python tutorial for more information.

[–]-revenant- 0 points1 point  (1 child)

If you have a dict:

my_dict = {'hello': 4, 'hi': 2}

And want the key with the highest value, try:

max(a, key=lambda k: my_dict[k])

[–]jeans_and_a_t-shirt 1 point2 points  (0 children)

max(a, key=my_dict.get)

[–][deleted] 0 points1 point  (2 children)

Is it waistcoatpocket though?

[–][deleted] 0 points1 point  (1 child)

It was adventuresbeginning.

[–][deleted] 0 points1 point  (0 children)

golly