comprehension problem

This is the place for queries that don't fit in any of the other categories.

comprehension problem

Postby abhi1988srivastava » Mon Sep 09, 2013 6:04 pm

Hi everyone,

I am new to python and trying to use tuple with sets through comprehension


Code: Select all
def assignedRoles(u):
   for i in U:
      for x,y in u:
         if i==x:
            print (x,y)

this gives me user with roles correctly but then i tried to do the same through comprehension like

Code: Select all
def assignedRoles(u):
   m={y for x,y in u if x=={k for k in U}}
   print (m)

Is my use of comprehension wrong since i am getting empty set as output?

I am calling the function as:


Please help!!!!


Posts: 11
Joined: Mon Sep 09, 2013 5:54 pm

Re: comprehension problem

Postby Somelauw » Mon Sep 09, 2013 7:43 pm

Code: Select all
def assignedRoles(u):
    print "\n".join(str((x, y))
            for i in U
            for(x, y) in u if i == x)
Join the #python-forum IRC channel on!
Posts: 82
Joined: Tue Feb 12, 2013 8:30 pm

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 13 guests