lundi 23 février 2015

Python: Small for statement without list

I'm trying to optimize my code. I'm trying to make my for-statement as short as possible. The problem is that the short for-statment is (ofcourse) "returning" a list. I want it to "return" a string.



b = [key2 for key2 in LUT_value.keys() if LUT_value[key2] == self.value]


Keys is a string, f.g it could be "Name". Problem is that b becomes:



b = ['Name']


And I'm returning a + ' ' + b which won't work. How could I work around this and still keep the small statement? If possible.


Aucun commentaire:

Enregistrer un commentaire