alter / modify a list as well as iterate on its items / objects

Peter Abel PeterAbel at gmx.net
Wed May 26 03:36:11 EDT 2004


Derek Basch <dbasch at yahoo.com> wrote in message news:<mailman.285.1085515057.6949.python-list at python.org>...
> Hello, 
> 
> Can anyone point me towards an article or explain
> how to properly alter a list as well as iterate
> on its items? For example:
> 
> input:
> 
> word = ["albert", "likes", "surfing!"]
> 
> for word in sentence:
>     word += "foo"
> 
> result:
> 
> word = ["albertfoo", "likesfoo", "surfingfoo"]
> 
> Thanks,
> Derek Basch
>
.
.
.

An solution No. 992345739219242.... is:-):

>>> from operator import add
>>> word = ["albert", "likes", "surfing!"]
>>> map(add,word,['foo']*len(word))
['albertfoo', 'likesfoo', 'surfing!foo']
>>> 

Regards
Peter



More information about the Python-list mailing list