Reputation: 349
Is it possible to change the string list- and add letter 'y'
to each element in the list:
lis = ['dan','jim','roky']
Upvotes: 0
Views: 35
Reputation: 124
lis = ['dan','jim','roky']
p=map(lambda x: x+'y',lis)
Map is a built in function which takes first argument as the function and each of the next arguments are the iterator on which you want to iterate and update the value and returns list of result.
The lambda function is anonymous function which updates the value of elements lis.
For more info visit https://docs.python.org/2/library/functions.html
Upvotes: 1
Reputation: 122383
Use list comprehension:
>>> [x + 'y' for x in lis]
['dany', 'jimy', 'rokyy']
Upvotes: 2