curly-brace-aphobic?

Niki Spahiev spahievi at vega.bg
Mon Jan 29 16:14:51 EST 2001


29.1.2001, 19:30:30, D-Man wrote:

DM> On Mon, Jan 29, 2001 at 08:35:42AM -0600, Grant Griffin wrote:
DM> | C.Laurence Gonsalves wrote:
| >> 
DM> | ...
| >> I'm not sure why you need to be reminded whether something is a sequence
| >> or a dictionary.
DM> | 
DM> | I guess it's because sequences and dictionaries are conceptually very
DM> | different.  (You can tell, because we have a special word just to

DM> I'm not sure how different they are conceptually.  A dictionary is a
DM> collection (sequence) of data that is indexed by arbitrary keys.  A
DM> list is a collection (sequence) of data that is indexed by integers
DM> only.  It seems to me that a list is a special case of a dictionary.
DM> How about classes that implement __getitem__?  They perform the same
DM> operation, just according to their own rules.  If the class is written
DM> to follow the same rules a dictionary or a list follows, but do some
DM> extra magic on the side, it could be used in place of the
DM> dictionary/list without any modification to the client code.

DM> I think that the same syntax is used because they are the same
DM> operation, just slightly different restrictions/rules.

I often switch my implementations from using list to dicts and
vice versa. It helps that both use [] for indexing. I wish they share
more e.g. list.keys() instead of range(len(list)), list.values()
instead of map( None, .... )

-- 
Best regards,
 Niki Spahiev






More information about the Python-list mailing list