Reputation: 292
I want to write solve this in python a function a list of words and an integer n and returns the list of words that are longer than n i.e
retlist=list()
def retword(list,n):
for i in list:
if len(i)>=n:
retlist.append(i)
return retlist
I can easily do this using this function but I want to solve this using map, filter, reduce and lambda expressions. Something like this
map(lambda list,len:list[i] if len(list[i])> len, (list,len))
Upvotes: 0
Views: 81
Reputation: 27869
List comprehensions will do the job you need if a
is original list and n
is the desired length:
retlist = [i for i in a if len(i) >= n]
Upvotes: 0