ezoic

Wednesday, March 15, 2017

Python problem

Write a function find_longest_word() that takes a list of words and returns the length of the longest one. Use only higher order functions.

Solution:

class Solution:
    def longest1(self, list1):
        aa={}
        for item in list1:
            aa[item]=len(item)

        max1=0
        for key in aa.keys():
            if aa[key]>max1:
                max1=aa[key]
            else:
                max1=max1

        lkey=list(aa.keys())[list(aa.values()).index(max1)]

        return(lkey)

kk=Solution()

if __name__=="__main__":

    print(kk.longest1(["atr","i","ertuo","worutynd"]))

1 comment:

looking for a man

 I am a mid aged woman. I live in southern california.  I was born in 1980. I do not have any kid. no compliacted dating.  I am looking for ...