Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Rob Wolfe Newsgroups: comp.lang.python Subject: Re: Python 3 dict question Date: Fri, 06 May 2011 22:46:36 +0200 Organization: Aioe.org NNTP Server Lines: 21 Message-ID: <87pqnvr1zn.fsf@smsnet.pl> References: NNTP-Posting-Host: 2rGoQNolRk9jw3eVwM369A.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:exoK10PdEF59GVfXboakg7OlAn0= Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4865 dmitrey writes: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of course, I could use > for key, val in myDict.items(): > do_something > break > but maybe there is any better way? key, val = next(iter(myDict.items())) http://docs.python.org/py3k/library/stdtypes.html#dictionary-view-objects HTH, Rob