Dynamically making lists?
Brian Lee
senux at senux.com.NOSPAM
Mon Jun 4 06:09:43 EDT 2001
Bill Witherspoon wrote:
>
> Hi all,
>
> If I have a list ->
>
> L = ['one', 'two', 'three',......,'one thousand']
>
> and I want to split this into several lists with (say) two elements
> each ->
>
> m = ['one', 'two']
> n = ['three', 'four']
> o = ['five', 'six'}
> ......
> zz = ['nine hundred ninety nine', 'one thousand']
>
> How would I do this? I don't know how many elements are in L before
> I run the program.
>
> It seems like I have to generate variable names on the fly?
> Maybe there's something simple I'm missing here.
>
> Any pointers would be appreciated.
>
> TIA,
> Bill.
How about to start from this code and edit for your own use.
for x in range(len(L) / 2):
tmp[x] = [L[x * 2], L[x * 2+ 1]]
--
Brian Lee <senux at senux.com>
* Please remove NOSPAM in my email adress to reply to me.
More information about the Python-list
mailing list