Artificial creating of [Lists], is it possible? the best way...
Chris Angelico
rosuav at gmail.com
Fri Nov 17 11:08:56 EST 2017
On Sat, Nov 18, 2017 at 2:29 AM, eth0 <ethernet.zero at gmail.com> wrote:
> On 2017年11月17日 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
Those are semantically different though.
ChrisA
More information about the Python-list
mailing list