generating list of sub lists

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Sep 17 09:36:55 EDT 2007


On Mon, 17 Sep 2007 20:52:14 +1000, Ross Wilson wrote:

> cesco wrote:
>> Hi,
>> 
>> is there a one-liner to accomplish the following task?
>>>From the list
>> l = ['string1', 'string2', 'string3'] generate the list of lists
>> l = [['string1'], ['string1', 'string2'], ['string1', 'string2',
>> 'string3']]
>> 
>> Any help would be appreciated.
>> 
>> Thanks
>> Francesco
>> 
>> 
> l = [l, l]
> 
> Ross


Did you *try* your suggestion before posting?

>>> l = ['string1', 'string2', 'string3']
>>> assert [l, l] == [['string1'], ['string1', 'string2'], 
... ['string1', 'string2', 'string3']]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError


What you've suggested doesn't even come close to what the Original Poster 
is asking for.


-- 
Steven



More information about the Python-list mailing list