Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51179
| Date | 2013-07-24 17:59 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Python 3: dict & dict.keys() |
| References | <mailman.5024.1374628577.3114.python-list@python.org> <51ef37e3$0$29971$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5075.1374713993.3114.python-list@python.org> (permalink) |
On 07/23/2013 07:11 PM, Steven D'Aprano wrote: > On Tue, 23 Jul 2013 18:16:08 -0700, Ethan Furman wrote: >> >> So now, in Python 3, .keys(), .values(), even .items() all return these >> 'view' thingies. >> >> And everything I thought I knew about when to use one or the other went >> out the window. > > Surely not. The fundamental behaviour of Python's data model hasn't > changed. Poetic effect. Dramatic license. Blah blah. ;) > Repeat after me: "In Python 2, d.keys() returns a list of keys, so if I > want a list of keys in Python 3, call list explicitly list(d.keys())." Actually, I would recommend `list(d)`, which also works the same in both 2 and 3. -- ~Ethan~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python 3: dict & dict.keys() Ethan Furman <ethan@stoneleaf.us> - 2013-07-23 18:16 -0700
Re: Python 3: dict & dict.keys() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-24 02:11 +0000
Re: Python 3: dict & dict.keys() Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-24 09:02 -0600
Re: Python 3: dict & dict.keys() Ethan Furman <ethan@stoneleaf.us> - 2013-07-24 17:59 -0700
Re: Python 3: dict & dict.keys() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-25 05:57 +0000
Re: Python 3: dict & dict.keys() Ben Finney <ben+python@benfinney.id.au> - 2013-07-25 12:20 +1000
csiph-web