On Wed, Jul 2, 2008 at 6:31 AM, Daniele <[EMAIL PROTECTED]> wrote:
>>> If I have a set of numbers, or strings etc. which have been generated and I 
>>> then want to do something with them, for example a sum function call.  Is 
>>> the best way to put those items in a list, or similar container, before 
>>> applying the function.
>>
>> Not only "best" but "necessary". the sum () builtin takes an
>> iterator -- often a list, but needn't be -- of numbers.
>
> I'm a total newbie, but wouldn't it be possible to use a set (from
> which I think you can get an iterator)?

Sets and lists are not interchangeable. A set removes duplicates, is
not ordered and has a fast membership test; a list preserves
duplicates, is ordered and is relatively slow for membership testing.
Members of a set must be hashable, so you can't put lists and dicts
into a set; members of a list can be any object.

Yes, you can get an iterator from a set (and a list).

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to