[Chicago] Making a list of strings
verisimilidude at gmail.com
Mon Oct 19 20:08:52 CEST 2009
OK fellow pythonistas, can anyone explain what is going on here?
I'm using a recent, but not most recent, version of Python.
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)]
I want a list with a string value in it. I make a sample string to
put in a list.
In : s='string'
The obvious way gives me something different but expected
In : list(s)
Out: ['s', 't', 'r', 'i', 'n', 'g']
So I try appending something to a newly created empty list
In : y=list().append(s)
And I get a null value. This is unexpected,
In : y
since doing the steps independantly gives me what I want.
In : y=list()
In : y.append(s)
In : y
I want to pass this as a parameter and it seems non-pythonic to have
to create a variable and then pass it when all I want is a single use.
Any ideas for a better work-around?
More information about the Chicago