Hacker News new | past | comments | ask | show | jobs | submit login

Being extremely pedantic, omitting the outer ()s is legal for a generator comprehension. That is, the following are equivalent:

  foo(x for x in xs)

  foo((x for x in xs))

  gen = (x for x in xs)
  foo(gen)
But these are not the same as:

  foo([x for x in xs]

  lst = [x for x in xs]
  foo(lst)
It doesn't matter in this tiny example, but the difference between generators and lists can be very very important when working on very large amounts of data (e.g. processing a big text corpus), or a potentially-infinite stream of data.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: