Ich habe eine Liste von Wortpaaren und versuche, sie als Daten für NetworkX zum Lesen vorzubereiten. Ein Teil des Skripts besteht darin, über die Paare zu iterieren, um sie den ID-Nummern zuzuordnen (siehe Code unten). Dieser Code löst einen Index out of range
Fehler aus, den ich überwinden muss. Was ist der Fehler hier?Listenindex außerhalb des Bereichs
coocs = [['parttim;work'], ['parttim;work'],['parttim;visit'], ['parttim;site'], ['parttim;uncl'], ['parttim;home'], ['parttim;onlin']]
unique_coocs = list(set([row[0] for row in coocs])) # remove redundance
ids = list(enumerate(unique_coocs)) # creates a list of tuples with unique ids and their names for each word in the network
keys = {name: i for i, name in enumerate(unique_coocs)} # creates a dictionary(hash map) that maps each id to the words
links = [] # creates a blank list
for row in coocs: # maps all of the names in the list to their id number
try:
links.append({keys[row[0]]: keys[row[1]]})
except:
links.append({row[0]: row[1]})
Welche Linie fein ist der Fehler auf? –
Dies: 'links.append ({row [0]: row [1]})' – textnet
Es würde helfen, die gesamte Fehlermeldung zu geben. – Joel