Saturday, December 4, 2010

Re: List compare is there something better than a double loop?

very cool thanks, i knew it was a lack of api knowledge on my part.

On Dec 2, 10:53 pm, Aaron Sterling <aaronasterl...@gmail.com> wrote:
> > I'm building a store that has a product_list (class ProductList:
> > store, name, description) that contains .products (class Product:
> > name, description, price etc...)
>
> If you're expecting them to be in the same order, you could do
>
>      all(product == cartitem.product for product, cartitem in
> itertools.izip(cartitems, products))
>
> This would be True if they're the same and false otherwise. If you want an
> order insensitive  comparison, you have:
>
>     set(products) == set(cartitem.product for cartitem in cartitems)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate