Python 3.6.x
I've got a defaultdict, which is named xref_to_records
. It has got strings as keys, and lists as values.
for k, v in xref_to_records.items():
print(type(k))
print(type(xref_to_records[k]))
break
It produces:
<class 'str'>
<class 'list'>
What I'm trying to do is to iterate through its items to compare the values list of a key against the next one. I know this question was probably already answered somewhere, but I couldn't figure to make work any of the provided approaches.
I've tried to iterate through the lenght of keys, but it doesn't work.
keys = xref_to_records.keys()
for i in range(len(keys)):
this_key = keys[i]
It raises me a TypeError:
TypeError: 'dict_keys' object does not support indexing
I've tried also to iterate through keys using next()
but unsuccessfully.
frick = None
for k,v in iter(xref_to_records.items()):
if k != frick:
res = next(k, None)
print(res)
break
Again a TypeError :
TypeError: 'str' object is not an iterator
Expected output
for k, v in xref_to_records.items():
somefunctions(k)
somefunctions(next(k))