Skip to content

Instantly share code, notes, and snippets.

@kimdwkimdw
Created January 11, 2012 09:06
Show Gist options
  • Save kimdwkimdw/1593822 to your computer and use it in GitHub Desktop.
Save kimdwkimdw/1593822 to your computer and use it in GitHub Desktop.
Get Longest Word From List
# available above python 2.6
from multiprocessing import Pool
def extractMaxLen( l ):
assert(len(l)>0)
elem,elemLen = l[0],len(l[0])
for idx in xrange(1, len(l)):
if len(l[idx]) > elemLen:
elem,elemLen = l[idx],len(l[idx])
return elem
if __name__ == '__main__':
lists = [ ["aaaa","aa","a" ],\
["aaaaaaaaaaaaa","aa","aaaaa"]]
result = []
pool = Pool(processes=4)
print extractMaxLen(pool.map( extractMaxLen, lists))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment