May I drop list bracket from list?
Ben Bacarisse
ben.lists at bsb.me.uk
Thu Apr 23 07:21:53 EDT 2015
subhabrata.banerji at gmail.com 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
does.
<snip>
--
Ben.
More information about the Python-list
mailing list