[Python-ideas] question - 'bag' type

Bruce Leban bruce at leapyear.org
Thu Apr 15 07:22:13 CEST 2010


The example you give is a dict aside from syntax. What makes it bag-like? Do
you expect that I can write

b = bag(foo=bar, foo=car)

But I'd hardly expect b.foo == bar or b.foo == car as you suggest.

--- Bruce
http://www.vroospeak.com


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 :)
>
> thanks,
> --t
> --
> C. Titus Brown, ctb at msu.edu
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100414/2cc7c69a/attachment.html>


More information about the Python-ideas mailing list