0

I use this code:

cur.execute("SELECT * FROM seats WHERE Day = 'S' AND Booked = 'N' AND Disabled = 'Y'")
for number, rows in groupby(cur, key=lambda r: r[0][0]):
    print 'Disabled seats available : ', ', '.join([r[0] for r in rows])

It Groups the data together to give the following answer:

Disabled seats available :  A1, A14
Disabled seats available :  B1, B16
Disabled seats available :  C1, C17
Disabled seats available :  D1, D19
Disabled seats available :  E1, E20
Disabled seats available :  F1, F20
Disabled seats available :  G1, G19
Disabled seats available :  H1, H19
Disabled seats available :  J1, J19
Disabled seats available :  K1, K19
Disabled seats available :  L1, L15

But i want the seats to be displayed in the following manner:

Disabled seats available: A1,A14,B1,B16

Like with no lines inbetween each one?

Is there a way to do this?

3
  • Then why use groupby in the first place? Commented Feb 14, 2013 at 17:01
  • because i have a whole other section that doesnt display disabled seats where in which groupby is actually useful. Commented Feb 14, 2013 at 17:02
  • I know, you based that on my answer, but in this case, there is no need to group your seats. Commented Feb 14, 2013 at 17:02

1 Answer 1

1

Simply remove the groupby call, and just use the rows from your cursor directly:

print 'Disabled seats available : ', ', '.join([r[0] for r in cur])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.