Accessing container's methods
Chris Angelico
rosuav at gmail.com
Mon Dec 7 17:02:33 EST 2015
On Tue, Dec 8, 2015 at 8:38 AM, Terry Reedy <tjreedy at udel.edu> wrote:
>> def list_actors( self ):
>> h=[]
>> for n in self.actors:
>> h.append( n.get_name() )
>> return h
>
>
> return list(self.actors) # or perhaps even faster
> return self.actors[:]
Not identical semantics. This is a use-case for a comprehension:
return [n.get_name() for n in self.actors]
(although I would eschew the getter in favour of just "n.name")
ChrisA
More information about the Python-list
mailing list