curly-brace-aphobic?
D-Man
dsh8290 at rit.edu
Tue Jan 30 18:15:14 EST 2001
More information about the Python-list mailing list
Tue Jan 30 18:15:14 EST 2001
- Previous message (by thread): curly-brace-aphobic?
- Next message (by thread): curly-brace-aphobic?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Jan 30, 2001 at 10:30:51AM -0800, Grant Griffin wrote: | In article <mailman.980870616.378.python-list at python.org>, D-Man says... | > | ... | >I still maintain my postiion that a list is really a special case of a | >dictionary, on a theoretical level. | You snipped my next conclusion here. [snip] | This last one is how I tend to think of it. I _think of_ tuples as a special | case of lists: "tuples are read-only lists". Likewise, one can _think of_ | strings as special cases of lists: "strings are imutable lists that can | contain only characters". Like I said (and was snipped), at a practical level, I don't think of lists as a special case dictionary. I also dislike the "strings are immutable" feature, but I understand that it can help optimization and mutable strings are much less fun in C than other languages. (I can see why Guido et al wouldn't want to deal with mutable strings in the interpreter, though Finn would have much less trouble with it in Jython) (no need to start a discussion here, I can deal with it :-)) If you wanted to implement a list as a dict, you could remove an item from the middle and adjusting the indexes by having the remove() function take all the higher indexes and switch the values, then deleting the highest index from the list of keys. Of course, using a series of linked nodes is much easier and faster. Nothing that really bothers people developing applications, just those who want to think of various ways to achieve the same result and then consider the tradeoffs. | | But if we try to generalize a relationship between dictionaries and lists, we | find that we can make neither a special case of the other--at least without | stretching it pretty far. | | Given the "indexers" hierarchy at top, the Python rule seems to be "All indexers | are indexed using square braces". Those who find Python's bracing "consistent" | evidently are evaluating "consistency" in terms of this rule. | | However, the rule that I seem to want to apply is "All indexers are indexed | using the style of brace used to bind them." (If a certain style of brace is | good enough to bind a variable, why isn't it good enough to _access_ a | variable?) That being said, it may not be possible (and it certainly isn't | desirable) to index strings and tuples using this rule. I think the purpose of the [] and the {} in list/dict construction is syntactic sugar for a factory function (or a class ctor). I can't think of any other reason for them (and for the difference). There could be a function make_dict() that takes a series of 2-tuples with the first element being the key and the second being the value, but I think the {} is simpler to type ;-). | | But I see no reason why curly braces could not be used for this purpose. | | explict-is-better-than-implicit-ly y'rs, | | =g2 | p.s. Just for the record, I'm not recommending any change to Python--because | the needs of backwards compatibility would undoubtedly lead to the dreaded "more | than one way to do it" <wink>. I was just asking a question. Thanks to all for | the many kind answers. | -D
- Previous message (by thread): curly-brace-aphobic?
- Next message (by thread): curly-brace-aphobic?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list