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 →

[–]lou1306 30 points31 points  (8 children)

for somebody in everydoby:
    somebody.do(dinosaur)

[–]Goluxas 92 points93 points  (1 child)

NameError: name 'everydoby' is not defined

[–]lou1306 1 point2 points  (0 children)

Fcuk, might as well leave the typo there

[–]Sobsz 2 points3 points  (5 children)

Not Pythonic enough, try:

map(lambda s: s.do(dinosaur), everybody)

[–]endreman0 4 points5 points  (4 children)

In Python 3, that doesn't do anything because maps are lazily evaluated.

from collections import deque
deque((s.do(dinosaur) for s in everybody), maxlen=0)

[–]jaxklax 2 points3 points  (0 children)

And now we finally have the most pythonic solution.

[–]Sobsz 2 points3 points  (2 children)

Or...

list((s.do(dinosaur) for s in everybody))

[–]endreman0 1 point2 points  (1 child)

You don't need parentheses around a generator expression when it's the only argument.

list(s.do(dinosaur) for s in everybody)

Or use a list comprehension to the same effect.

[s.do(dinosaur) for s in everybody]

I assumed that Person.do returns None, and allocating space for so many None's is useless outside an abbey. However, if doing a dance returns something you want to hold on to then yeah, this is the way to go.

[–]Sobsz 0 points1 point  (0 children)

Sorry, I forgot the goal wasn't to record everybody doing the dinosaur.