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


Groups > comp.lang.python > #68579

Re: Dictionaries

From John Gordon <gordon@panix.com>
Newsgroups comp.lang.python
Subject Re: Dictionaries
Date 2014-03-20 14:19 +0000
Organization PANIX Public Access Internet and UNIX, NYC
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>

Show all headers | 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