May I drop list bracket from list?

Ben Bacarisse ben.lists at
Thu Apr 23 13:21:53 CEST 2015

subhabrata.banerji at writes:

> I am trying to read a list of files as 
> list_of_files = glob.glob('C:\Python27\*.*')
> Now I am trying to read each one of them, 
> convert into list of words, and append to a list
> as.
> 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.

You probably want list.extend(fword) here.  Python's ternimology is a
little quirky here -- in some other languages (ntable the mother of all
list langiages, Lisp), the append function does what Python's extend


More information about the Python-list mailing list