0

我使用这段代码:

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])

它将数据分组在一起以给出以下答案:

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

但我希望座位以下列方式显示:

Disabled seats available: A1,A14,B1,B16

就像每个之间没有线条?

有没有办法做到这一点?

4

1 回答 1

1

只需删除groupby调用,然后直接使用光标中的行:

print 'Disabled seats available : ', ', '.join([r[0] for r in cur])
于 2013-02-14T17:02:03.497 回答