[Python-ideas] question - 'bag' type
C. Titus Brown
ctb at msu.edu
Thu Apr 15 07:31:17 CEST 2010
On Wed, Apr 14, 2010 at 10:20:51PM -0700, Chris Rebert wrote:
> On Wed, Apr 14, 2010 at 10:12 PM, C. Titus Brown <ctb at msu.edu> wrote:
> > On Thu, Apr 15, 2010 at 12:08:26AM -0500, Daniel Stutzbach wrote:
> >> On Thu, Apr 15, 2010 at 12:02 AM, C. Titus Brown <ctb at msu.edu> wrote:
> >> > this seems like the right forum to ask -- is there a reason why Python
> >> > doesn't have a 'bag' builtin type, e.g.
> >> >
> >> Python 2.7 and 3.1 have a Counter type, that is similar to (but not
> >> identical to) that recipe:
> >>
> >> http://docs.python.org/py3k/library/collections.html#collections.Counter
> >
> > Huh, seems like a different use case from mine -- I just would like to be able
> > to refer to dictionary keys as attributes. ??So I guess the cookbook recipe
> > distracted you from my real interest, which is the short notation:
> >
> > ?? b = bag(foo=bar, bif=baz)
> >
> > ?? assert b.foo == bar
> > ?? assert b.bif == baz
> >
> > Still curious :)
>
> Also, that's not a bag at all. Seems you're looking for something
> similar to namedtuple:
> http://docs.python.org/dev/library/collections.html#collections.namedtuple
>
> For the record, a bag is an unordered collection that permits
> duplicate elements. Sort of like an unordered, unindexable list, or a
> set that allows duplicate elements.
> It's got nothing whatsoever to do with being able to access elements
> using attribute syntax.
Thanks!
--titus
--
C. Titus Brown, ctb at msu.edu
More information about the Python-ideas
mailing list