On Wed, 09 Apr 2014 21:09:37 +0800, length power wrote:

> words = ["x1", "x2", "x3", "x4", "x5"]
> words.append(words.pop(2))
> words.append(words.pop(2))
> words
> ['x1', 'x2', 'x5', 'x3', 'x4']
> why i can't write it as:
> 
> [words.append(words.pop(2)) for i in range(0,2)]
> 
>>>> [words.append(words.pop(2)) for i in range(0,2)]
> [None, None]

You can, but you don't want to.  At this point, even though the
comprehension returned something else, words contains what you want.

HTH,
Dan
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to