Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68579

Re: Dictionaries

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 <gordon@panix.com>
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 <lgete6$fom$1@reader1.panix.com> (permalink)
References <CANXBEFogXsze6WByg_iCit-oLEQK-RXsgJCDM=ocZ7JPNgdb8g@mail.gmail.com> <mailman.8300.1395322251.18130.python-list@python.org>
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

Show key headers only | View raw


In <mailman.8300.1395322251.18130.python-list@python.org> ishish <ishish@domhain.de> 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'.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Dictionaries ishish <ishish@domhain.de> - 2014-03-20 13:11 +0000
  Re: Dictionaries John Gordon <gordon@panix.com> - 2014-03-20 14:19 +0000

csiph-web