<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>I've got a question about using list comprehensions.<br><br></div>I've got a piece of code that is making a MySQL query:<br>sql = "SELECT tail FROM aircraft_state WHERE airline='WN'"<br></div>c.execute(sql)<br><br></div>I'm currently using a loop to get the values into a list:<br></div>rows = c.fetchall()<br></div>for row in rows:<br></div> comm = row[0]<br></div><br></div>since the return value from MySQL is delivered as tuples. I'd like to use a list comprehension to build my final list (no important reason, I just want to learn how). I tried:<br><br></div>comm = [x for x in c.fetchall()][0]<br><br></div>but that just gives me the first tuple. If I use:<br><br></div>comm = [s for x in c.fetchall()]<br><br></div>I end up with a list of tuples. Any suggestions as to how I could do this without using a for loop?<br><br clear="all"><div><div><div><div><div><div><div><div><div><div><div><div><div><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>--------------------------<br>Dan Mahoney<br><a href="mailto:catdude@gmail.com" target="_blank">catdude@gmail.com</a><br></div><div>Skype: catdude60440<br></div><div><br>"How you behave towards cats here below determines your status in Heaven."<br>Robert Heinlein<br><br>"There are two means of refuge from the miseries of<br>life - music and cats" - Albert Schweitzer</div></div></div></div></div>
</div></div></div></div></div></div></div></div></div></div></div></div></div></div>