The word 'sequence' here doesn't mean an exclusive category. In a sense,
all sequences are really mappings - they "map" a range of integers to
values.
From the standpoint of accepting an argument, we really don't care
whether something is a sequence or a mapping, we care about what we can
do with it. The approach that I'd like to take is to identify the use
cases, and then devise tests that indicate whether those use cases can
be applied.
So to avoid confusion, let's drop 'sequence' and 'mapping' for the
moment, and instead think about use cases:
appendable( iterable ):
-- An iterable that can be appended to
-- Test: hasattr( append )
-- (Probably also need to test the signature of append)
associative( indexable ):
-- An iterable that contains associative pairs of items,
where the item pairs can be iterated over
-- Test: hasattr( iteritems )
Marcin 'Qrczak' Kowalczyk wrote:
> Talin <[EMAIL PROTECTED]> writes:
>
>
>>sequence( indexable ):
>> -- an indexable in which the indexes are successive integers
>> -- Test: isinstance( index_type, int )
>
>
> I don't understand. How would this test distinguish [] being a
> sequence from {} not being a sequence?
>
>
>>mapping( indexable ):
>> -- an indexable in which the indices are hashable values:
>> -- Test: hashable( index_type )
>> -- (Also test for immutable if its feasible)
>
>
> And this on the contrary?
>
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com