How does this function work?

G

Guest

... return [x for x in range(3), 1, y for y in range(4), 4]
...
>>> f(3) [[0, 1, 2], [0, 1, 2], 1, 1, 3, 3]
>>>

I've been staring at it for 15 minutes and I'm no closer to understanding than when I started.

Why is this even legal Python syntax? What is going on that makes it return what it does?

Jp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top