Empty value when iterating a dictionary with .iteritems() method
- by ptpatil
I am having some weird trouble with dictionaries, I am trying to iterate pairs from a dictionary to pass to another function. The loop for the iterator though for some reason always returns empty values.
Here is the code:
def LinktoCentral(self, linkmethod):
if linkmethod == 'sim':
linkworker = Linker.SimilarityLinker()
matchlist = []
for k,v in self.ToBeMatchedTable.iteritems():
matchlist.append(k, linkworker.GetBestMatch(v, self.CentralDataTable.items()))
Now if I insert a print line above the for loop:
matchlist = []
print self.ToBeMatchedTable.items()
for k,v in self.ToBeMatchedTable.iteritems():
matchlist.append(k, linkworker.GetBestMatch(v, self.CentralDataTable.items()))
I get the data that is supposed to be in the dictionary printed out. The values of the dictionary are list objects. An example tuple I get from the dictionary when printing just above the for loop:
>>> (1, ['AARP/United Health Care', '8002277789', 'PO Box 740819', 'Atlanta', 'GA',
'30374-0819', 'Paper', '3676'])
However, the for loop gives empty lists to the linkworker.GetBestMatch method. If I put a print line just below the for loop, here is what I get:
Code:
matchlist = []
for k,v in self.ToBeMatchedTable.iteritems():
print self.ToBeMatchedTable.items()
matchlist.append(k, linkworker.GetBestMatch(v, self.CentralDataTable.items()))
## Place holder for line to send match list to display window
return matchlist
Result of first iteration:
>>> (0, ['', '', '', '', '', '', '', ''])
I literally have no idea whats going on, there is nothing else going on while this loop is executed. Any stupid mistakes I made?