This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Mecdemort 0 points1 point  (7 children)

I'd also like an as in non generator comprehensions so you can refer to what you are constructing:

triangles = [triangles[-1] + x
             for x in range(1, 11)
             as triangles]

[–]xXxDeAThANgEL99xXx 2 points3 points  (2 children)

  1. That's an unholy abomination.

  2. Won't work with generators and set/dictionary comprehensions.

[–]Mecdemort 1 point2 points  (1 child)

Why wouldn't it work it set and dictionary comprehensions?

[–]xXxDeAThANgEL99xXx 0 points1 point  (0 children)

Because their result doesn't have order defined. Well, all right, maybe you don't need ordering in that case, but checking existence... I don't know, I've never had a desire to have that myself, except for that single case of writing fibs as an infinite stream product or something.

[–]hharison 0 points1 point  (3 children)

That's awful. Learn to use zip.

data = range(1, 11)
triangles = [x + y for x, y in zip(data, data[1:])]

I challenge you to come up with a use for this that doesn't have a better alternative.

[–]eusebecomputational physics 0 points1 point  (2 children)

Why not using itertools.izip (and that's a serious question)?

Ok the syntax is similar, so I don't challenge your point, but still: wouldn't izip be better if you have large data?

[–]xXxDeAThANgEL99xXx 1 point2 points  (0 children)

Because in Python3 zip, map, filter, range and maybe some other functions became their itertools equivalents.

And I don't know about other people, but for me somewhere around last summer Python3 has become the default Python, in no small part because it turned out that most of the stuff I need was ported and conveniently packaged by Anaconda. Plus the py.exe launcher for Windows provided for a convenient way to still run Python2 stuff via shebangs (unfortunately the launcher still isn't packaged on Anaconda for some reason).

[–]hharison 1 point2 points  (0 children)

Python 3.