I have a list of codes coming from a csv file:
file_path = 'c:\\temp\\list.csv'
csvfile = open(file_path, 'rb')
reader = csv.reader(csvfile, delimiter=';')
rr = []
for sor in reader:
if sor[1][0] == '1':
rr.append(sor)
print type(rr)
<type 'list'>
set (rr)
Traceback (most recent call last):
File "<pyshell#85>", line 1, in <module>
set (rr)
TypeError: unhashable type: 'list'
If I do the very same on an other list coming from a database it works fine:
cur.execute('select code from mytable')
res = cur.fetchall()
res1 = []
res1.append(x[0] for x in res)
print type(res1)
<type 'list'>
set(res1)
set(['13561255', '11120088'])
What is the difference between rr and res1 as both are of list type?
Actually I'm looking for records in the database which doesn't exist in the csv file by doing
result = list(set(res1) - set(rr))
How can I achieve this (maybe in a more optimal/faster way)?