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

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,678
Latest member
Aniruddha Das

Latest Threads

Top