[SciPy-user] help with list comprehensions

Matthieu Brucher matthieu.brucher@gmail....
Wed Aug 1 13:53:21 CDT 2007


hi,

list comprehension creates a new list with the return of a function. Here,
w.append(data) returns None, so you have a list of None.
More simple :

>>> x + y

Matthieu

2007/8/1, Stephen Yang <scyang@nist.gov>:
>
> Hello everyone,
>
> I have a question about list comprehensions. I would like to append data
> to an existing list using a list comprehension. Unfortunately, what I
> have tried does not seem to work:
>
> >>> y = [5, 1, 3, 5]
> >>> x = ['a', 'b']
> >>> new = [x.append(data) for data in y]
> >>> new
> [None, None, None, None]
>
> Can anyone help? Thanks very much in advance.
>
> Stephen
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070801/8e6ba794/attachment.html 


More information about the SciPy-user mailing list