May I drop list bracket from list?

Jean-Michel Pichavant jeanmichel at sequans.com
Thu Apr 23 07:12:48 EDT 2015


----- 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

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list