RFC: Viper: yet another python implementation

John Max Skaller skaller at maxtal.com.au
Sun Aug 15 12:24:24 EDT 1999


On 11 Aug 1999 10:59:10 -0400, Michael Haggerty <mhagger at blizzard.harvard.edu> wrote:

>skaller at maxtal.com.au (John (Max) Skaller) writes:
>> 	3) 'in' applies to dictionaries 'as if a sequence of keys were used'
>
>At first I thought `hey that's cool!' since I'm kindof sick of typing
>has_key() all the time.  But then I realized that this is not really
>consistent with sequence types.
>
>    item in list     IMPLIES      list[something] == item
>
>but according to your definition,
>
>    item in dict     IMPLIES      list[item] == something
>
>where in each case `something' is undetermined.  I suggest you rethink
>this `feature'.

	I agree there are some difficulties here, which is why
I'm appealing to the Python community for ideas.

	There is an alternate possible definition:

	k,v in dict

which might make more sense:

	dict.has_key(k) and dict.get(k)

However the idea is that 

	x in Y

means 'x is a member of the set of elements of Y'
and for a list the 'set of elements of Y' is the
set of elements of the list, and for a dictionary
it is the set of keys of the dictionary.

In this way, the meaning is consistent for lists
and dictionaries. Furthermore,

	for x in Y: S(x)

is also well defined as executing S(i) for
each i in Y: for lists and tuples, in the order
of the list or tuple, for dictionaries either
in a random order, or in order of the sorted
keys.

John Max Skaller                ph:61-2-96600850              
mailto:skaller at maxtal.com.au       10/1 Toxteth Rd 
http://www.maxtal.com.au/~skaller  Glebe 2037 NSW AUSTRALIA




More information about the Python-list mailing list