Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Dictionaries Date: Thu, 20 Mar 2014 14:19:50 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 32 Message-ID: References: NNTP-Posting-Host: panix2.panix.com X-Trace: reader1.panix.com 1395325190 16150 166.84.1.2 (20 Mar 2014 14:19:50 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Thu, 20 Mar 2014 14:19:50 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:68579 In ishish writes: > The script [...] only creates batch1.csv. If the script only creates batch1.csv, that means Batch2 and Batch3 must be empty. > for k, v in myDict.items(): > if Batch1.has_key(k): > if k in Batch2.has_key(k): > Batch3[k] = v > else: > Batch2[k] = v > else: > Batch1[k] = v 'if k in Batch2.has_key(k):' is a very strange line of code. In fact, it should produce a syntax error if it were ever executed, because the 'in' keyword requires an iterable as the second part, and has_key() returns only True or False. Therefore, I would say that line of code never executes, which means that the preceding 'if Batch1.has_key(k)' statement always evaluates to False. Which therefore means that Batch2 and Batch3 never accumulate any items, matching your observed output. -- John Gordon Imagine what it must be like for a real medical doctor to gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.