Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105521
| From | "Marco S." <mail.python.org@marco.sulla.e4ward.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Suggestion: make sequence and map interfaces more similar |
| Date | 2016-03-22 20:54 +0100 |
| Message-ID | <mailman.34.1458721359.2244.python-list@python.org> (permalink) |
I noticed that the sequence types does not have these methods that the map types has: get(), items(), keys(), values(). It could seem useless to have them for sequences, but I think it will ease the creation of functions and methods that allow you to input a generic iterable as parameter, but needs to use one of these methods in case the parameter is a map. In one word, it will facilitate duck typing. For the same reason, I would suggest the introduction of a new map type, vdict, a dict that by default iterates over values instead over keys. So a vdict object "d" wiil have iter(d) == iter(d.values()), and should also have a count() method, like sequence types. Indeed sequences are, in my humble opinion, a specialized case of maps, when keys are numeric only, are always contiguous without gaps and start from 0. This way we will have a simpler way to let people to use sequences or maps indifferently, and let the code untouched.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Suggestion: make sequence and map interfaces more similar "Marco S." <mail.python.org@marco.sulla.e4ward.com> - 2016-03-22 20:54 +0100
Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-23 22:26 +1100
Re: Suggestion: make sequence and map interfaces more similar Marco Sulla <marcosullaroma@gmail.com> - 2016-03-26 01:18 +0100
Re: Suggestion: make sequence and map interfaces more similar Steven D'Aprano <steve@pearwood.info> - 2016-03-26 22:41 +1100
Re: Suggestion: make sequence and map interfaces more similar Marco Sulla <marcosullaroma@gmail.com> - 2016-03-26 01:35 +0100
Re: Suggestion: make sequence and map interfaces more similar Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-26 10:29 +0000
csiph-web