[Tutor] replacing a loop

2019-06-24 Thread johnf
Hi folks, I have the following loop (actually repeated many times ) def locChoices(self):     locDS = self.eslocation.getDataSet()     loc_Choices=['']     locKeys=[0]     for row in locDS:     loc_Choices.append(row['facility'])     locKeys.append(row['pkid'])

Re: [Tutor] replacing a loop

2019-06-24 Thread Peter Otten
johnf wrote: > Hi folks, > > > I have the following loop (actually repeated many times ) If you have repetetive code look into ways to parameterize it, like def choices(rows, choices_column, keys_column): ... > > def locChoices(self): > locDS = self.eslocation.getDataSet() > loc_Choice

Re: [Tutor] replacing a loop

2019-06-24 Thread Mats Wichmann
On 6/24/19 10:15 AM, johnf wrote: . > > 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. To amplify a tiny bit on

Re: [Tutor] replacing a loop

2019-06-24 Thread johnf
Actually I do not see a reply from Peter??  I don't have a clue what was said. I realize that performance is not a big issue in this case - of course an increase in speed is always welcome.  I was more interested in a better understanding of the list comprehensions.  Since I have so many

Re: [Tutor] replacing a loop

2019-06-24 Thread David L Neil
Hi John, On 25/06/19 4:15 AM, johnf wrote: Hi folks, I have the following loop (actually repeated many times ) def locChoices(self):     locDS = self.eslocation.getDataSet()     loc_Choices=['']     locKeys=[0]     for row in locDS:     loc_Choices.append(row['facil

Re: [Tutor] replacing a loop

2019-06-24 Thread johnf
Thank you - it worked!  I'm glad you are no longer sleepy! Actually I wanted the naming to remain consistent with the other loops So the name of the function/method (it is in a class) caused the use of the underscore locChoices == location choices def locChoices(self) cause me to use loc_Cho

Re: [Tutor] replacing a loop

2019-06-24 Thread Mats Wichmann
On 6/24/19 4:24 PM, johnf wrote: > Thank you - it worked!  I'm glad you are no longer sleepy! > > Actually I wanted the naming to remain consistent with the other loops > > So the name of the function/method (it is in a class) caused the use of > the underscore > > locChoices == location choices

Re: [Tutor] replacing a loop

2019-06-25 Thread Alan Gauld via Tutor
On 24/06/2019 17:15, johnf wrote: > def locChoices(self): >     locDS = self.eslocation.getDataSet() >     loc_Choices=[''] >     locKeys=[0] >     for row in locDS: >     loc_Choices.append(row['facility']) >     locKeys.append(row['pkid']) > > retu