Artificial creating of [Lists], is it possible? the best way...

eth0 ethernet.zero at gmail.com
Fri Nov 17 10:29:42 EST 2017


On Fri, 17 Nov 2017 00:04:16 +0000 in comp.lang.python, MRAB said:
>  On 2017-11-16 18:47, jakub.rajcok at gmail.com wrote:
> > Hello, im working on school project, its deck game Sorry!
> > I need to create specific lists:
> > My idea is about to using for
> > For i in range (n):
> >         i=[]
> > I know, that there is no possibility to make it from number, but
> > i havent idea, how to reach my wants Li/L"i"/L(i), how to make
> > possible for lists?
> > 
> > 
>  If you want multiple lists, make a list of lists:
> 
>  my_lists = []
> 
>  for i in range(n):
>       my_lists.append([])
> 
>  Then you can say my_lists[0], my_lists[1], etc.

It'd be even shorter using a list comprehension:

my_lists = [[] for i in range(n)]

And _even shorter still_ just using the multiply operator:

my_lists = [[]] * n



More information about the Python-list mailing list