[Tutor] replacing a loop
johnf
johnf at jfcomputer.com
Mon Jun 24 12:15:36 EDT 2019
Hi folks,
I have the following loop (actually repeated many times )
def locChoices(self):
locDS = self.eslocation.getDataSet()
loc_Choices=['<None>']
locKeys=[0]
for row in locDS:
loc_Choices.append(row['facility'])
locKeys.append(row['pkid'])
return loc_Choices,locKeys
where locDS is a tuple of dicts and a row is a dict.
Since I use a lot of similar loops to populate many dropdown controls I
started investigating the use of list comprehensions. But I can't
figure out how to use them in this loop and wonder if it will improve
the performance. The data is not very big - about a thousand rows -
give or take.
So what do you guys think?
Johnf
More information about the Tutor
mailing list