for in sequence problem... possible new operator to add to python
Aahz
aahz at pythoncraft.com
Thu Jul 10 13:31:04 EDT 2003
In article <5_gPa.8878$ru2.867718 at news20.bellglobal.com>,
Sean Ross <sross at connectmail.carleton.ca> wrote:
>"Adam Gent" <agentgt at yahoo.com> wrote in message
>news:3a8fc6c5.0307100816.634c83a3 at posting.google.com...
>>
>> I was fooling around subclassing a dictionary object and noticed that
>> when
>> I do the standard "for in <object-is-a-sequence>:" that I have no
>> control on how python gets that sequence.
>[snip]
>> However I want b to be the values with out doing:
>> for b in bl.values()
>
>You can do it as follows:
>
>class Blah(dict):
> def __iter__(self):
> return iter(self.values())
Ick. At the very least, return self.itervalues()
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"Not everything in life has a clue in front of it...." --JMS
More information about the Python-list
mailing list