May I drop list bracket from list?
Peter Otten
__peter__ at web.de
Thu Apr 23 07:52:19 EDT 2015
Jean-Michel Pichavant wrote:
> ----- Original Message -----
>> From: "Peter Otten" <__peter__ at web.de>
>> To: python-list at python.org
>> Sent: Thursday, 23 April, 2015 12:26:41 PM
>> Subject: Re: May I drop list bracket from list?
>>
>> subhabrata.banerji at gmail.com wrote:
>>
>> > Dear Group,
>> >
>> > list1=[]
>> > for file in list_of_files:
>> > print file
>> > fread1=open(file,"r").read()
>> > fword=fread1.split()
>> > list1.append(fword)
>> >
>> > Here the list is a list of lists, but I want only one list not
>> > list of lists.
>> There is also a dedicated extend() method that takes a list (actually
>> an
>> iterable) and appends all items in that list:
>>
>> list1.extend(fword)
>
> If both list1 and fword are lists, you can also write
>
> list1 = list1 + fword
> or
> list1 += fword
Yes, the can of worms is bottomless ;)
More information about the Python-list
mailing list