My Code is splitting up a file line by line into strings and extends them to a list.
I noticed that for cases where only one string is extended, the result will split up that string and extend it letter by letter to the empty list. If I delete [-1] the string remains intact, but the other strings will be extended aswell.
How can I prevent that string from being split up when extending it to the empty list?
searchstring = "abc dfe ghi" #resembles a searchline from a file
text = searchstring.split() #note: same thing happens if i add [-1] here
list1.extend(text[-1]) #I only want the last element of the string
So either the output is:
print list1
[abc, dfe, ghi]
or
print list1
[g, h, i]
but I need it this way
print list1
[ghi] #one entry for each line in the file
abc,dfe,ghisupposed to be string literals? It will be easier to help you if you could provide exact code which fully replicates your problem as well as the intended output.