Keep getting this split error, when trying to split up my list Word by Word, line by line.
I got a file which contains links, +20000 links. These links is in a list called "links"
my code so far:
import networkx as nx
# Create graph
network_graph = nx.Graph()
path = []
with open('paths_finished.tsv','r') as tsv:
paths = [line.strip().split('\t') for line in tsv]
newPath = paths[16:]
links = []
for line in newPath:
links.append(line[3:4])
newList = []
for i in links:
newList.append(i.split(';'))
print newList
The lenght of the links list = 51318. I want to split up the " ; " in every links in my list.
For example the first link in the file are:
['14th_century;15th_century;16th_century;Pacific_Ocean;Atlantic_Ocean;Accra;Africa;Atlantic_slave_trade;African_slave_trade'],
Then I want to split it up Word by Word, so I got:
['14th_century 15th_century 16th_century Pacific_Ocean Atlantic_Ocean Accra Africa Atlantic_slave_trade African_slave_trade'],
for line in newPathloop is either off, or entirely wrong (you'll only process the lastnewPath).;is replaced by ' ' (whitespace)? Or you want a list where each word is an element?lis your first list.x = [l[0].replace(';', ' ')](list with one string) |y = l[0].split(';')(list of words)links.append(line[3:4])should just belinks.append(line[3]).