Firstly, Given that you have a list of lists, I am going to assume that you are going to convert the given list from unicode to an UTF8 string. For this lets have a function convertList
which takes a list of lists
as an input
So your initial value for l
would be
[[u'Sentence 1 blabla.'],
[u'Sentence 2 blabla.'],
...]
Notice that this is a list of lists. Now for each list item, loop through the items within that list and convert them all to UTF8.
def convertList(l):
newlist = []
for x in l:
templ = [item.encode('UTF8') for item in x]
newlist.append(templ)
return newlist
l = [[u'Sentence 1 blabla.'], [u'Sentence 2 blabla.']]
l = convertList(l) # This updates the object you have
# Now do the filewrite operations here.
f = open('myfile.txt','w')
for iList in l:
for items in iList:
f.write(items+'\n')
f.close()
This will write to the file myfile.txt
as follows
Sentence 1 blabla.
Sentence 2 blabla.