Given a list of objects that all have a particular attribute, is there
a simple way to get a list of those attributes?

In other words:

  class Foo(object):
      def __init__(self, name):
          self.name = name

  foolist = [ Foo('a'), Foo('b'), Foo('c') ]

  namelist = []
  for foo in foolist:
      namelist.append(foo.name)

Is there a way to avoid the for loop and create 'namelist' with a single
expression?

--
========================================================================
Ian Pilcher                                         arequip...@gmail.com
-------- "I grew up before Mark Zuckerberg invented friendship" --------
========================================================================

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to