On 21-Nov-11 23:49, Charles Becker wrote:
Alan, Steve, future readers,
After some re-reading and hacking I was able to discover the solution. Since I
raised the question here it is :
[['{0}'.format(x+1), x+1] for x in range(size)]
Just to fill out some other refinements for your information
Alan, Steve, future readers,
After some re-reading and hacking I was able to discover the solution. Since I
raised the question here it is :
[['{0}'.format(x+1), x+1] for x in range(size)]
This will create the list with nested lists for whatever number 'size' is set
to. This should be good e
Steven and Alan,
Thank you for your comments!
Alan said:
>> Because you don't have a list comprehension. You can't put add arbitrary
>> code inside a square brackets [ ]. You have to follow the syntax for a
>> list comprehension:
This helps me understand a lot when looking back, I thought that a
On 22/11/11 00:10, Steven D'Aprano wrote:
Because you don't have a list comprehension. You can't put add arbitrary
code inside a square brackets [ ]. You have to follow the syntax for a
list comprehension:
listcomp = [expression for name in sequence]
not
listcomp = [expression for name in seq
Charles Karl Becker wrote:
I'm trying to use a list comprehension to build a list with a variable
number of lists nested within it (ideally eventually going several
levels of nesting). However I seem to be observing some strange
behavior and was wondering if anyone could take a look at this and
I'm trying to use a list comprehension to build a list with a variable
number of lists nested within it (ideally eventually going several
levels of nesting). However I seem to be observing some strange
behavior and was wondering if anyone could take a look at this and
tell me if what I'm trying to