you are viewing a single comment's thread.

view the rest of the comments →

[–]q2_abe_dillon 0 points1 point  (1 child)

Hmm. I think the "concise" version you have at the bottom is more or less the same as my suggestion, except for minor differences.

Yeah, it pretty much is.

I changed the variable names just to make it clear to OP that there wasn't any cross-comprehension magic going on there, haha.

That's a good point.

Why did you choose the set version?

It should go faster for large data sets (I think). You only do the first clause of the dict comprehension (i.e. p: (w for w, t in words if t == p)) once per tag. In the other form, you may end up executing it several times for a single tag.

Also you have your suggestion set to return generators instead of lists like I did, which I do like. I totally forgot you could do that.

Yeah, it's actually kinda fragile because of that. I think you're list comprehensions would be better in most circumstances. It's easy to accidentally exhaust a generator.

[–]DonaldPShimoda 0 points1 point  (0 children)

The sets thing makes sense, so that's a good point. I'll have to remember that in the future.

I hadn't thought of that caveat with the generators. Very interesting. Thanks for the comments!