I was trying to learn set comprehensions and came up with a query:

Here r is a set of tuples.

- Code: Select all
`def e3():`

r3=set()

return {(r3.add((u,v))(for u,w1 in r if w1==w2) for w2,v in r)}

How can I make this work? It shows error for first forloop. I wanted to demonstrate:

- Code: Select all
`def e3():`

r3=set()

for w2,v in r:

for u,w1 in r:

if w1==w2:

r3.add((u,v))

return r3

Please help..

Thanks

Abhinav