LED Fantom
LED Fantom

Reputation: 1373

What type of iterable is "x for x in y"?

I've been confused of list comprehension in Python, although its shorthand doing for loop is very convenient. I'm not sure if what's in the join() function's parameter below is list comprehension since usually you put [] around to show it's a list comprehension.

My question: What's the type of iterable produced by str(x) for x in res[::-1] in join() below? Thanks.

ex,

''.join( str(x) for x in res[::-1] )

Upvotes: 1

Views: 550

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191983

This is a generator expression, which itself is an iterable.

The square brackets could still be added, however. Refer Joining strings. Generator or list comprehension?

Upvotes: 2

Related Questions