python - Why am I getting an "Unhashable type: 'list' " error? -
i have huge list ( mylist
) contains strings this:
>>> mylist[0] 'akaka d hi -1 -1 1 1 1 -1 -1 1 1 1 1 1 1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 1 1 1 1 1 1 0 0 1 -1 -1 1 -1 1 -1 1 1 -1'
now, want take 0, 1 , -1 , make list them, can make list name @ first part of string values of list of 0, 1 , -1... after time come monstrosity
dictionary = {} x in range(len(mylist)-1): dictionary.update({mylist[x].split()[0],[]}),[mylist[0].split()[k] k in range(3,len(mylist[0].split()))]})
but when try out in commandline, error:
>>> x in range(len(mylist)-1): ... dictionary.update({mylist[x].split()[0],[mylist[0].split()[k] k in range(3,len(mylist[0].split()))]}) ... traceback (most recent call last): file "<stdin>", line 2, in <module> typeerror: unhashable type: 'list'
one way this:
dictionary = {} x in mylist: p = x.find('1') if p > 0 , x[p-1] == '-': p -= 1 dictionary[x[0:p].strip()] = x[p:].split()
Comments
Post a Comment