abhi1988srivastava wrote:If I suppose, students and teachers are my sets containing tuples and supposing 1st element of tuple is the ID then:
j=[j++ for student in students for teacher in teachers if teacher is equal student ]
I don't know how to correctly transform my sql query into the comprehension like above (which is wrong).
If something does not work, it may help to split it into multiple lines, just for clarity. Also, use print
for easy debugging.
- Code: Select all
my_results = 
for student in students:
for teacher in teachers:
print student, teacher
if student == teacher:
my_results.append(student) # or whatever you really want to do here