locs2
is a list with strings, not a list of lists. As such you are trying to write individual strings as a row:
for values in sorted(locs2):
writer.writerow(values)
Here values
is a string, and writerow()
treats it as a sequence. Each element of whatever sequence you pass to that function will be treated as a separate column.
If you wanted to write all locations as one row, pass the whole list to writer.writerow()
:
writer.writerow(sorted(locs2))
If you wanted to write a new row for each individual location, wrap it in a list first:
for location in sorted(locs2):
writer.writerow([location])
You don't need to string u
prefixes from strings; that's just Python telling you you have Unicode string objects, not byte string objects:
>>> 'ASCII byte string'
'ASCII byte string'
>>> 'ASCII unicode string'.decode('ascii')
u'ASCII unicode string'
See the following information if you want to learn more about Python and Unicode:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…