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 > > def locChoices(self) cause me to use loc_Choices in the code. > > I am torn about the readability of the code - at least in my mind I can > read the loop a lot easier than I can read the comprehension.
That's actually fine. There are plenty of people who don't think comprehensions are more readable, at least unless they're really simple. It's an odd self-fulfilling prophecy: if you use them a lot, they usually start to feel more familiar. If you don't like the look of them, you don't tend to use them, and they never reach that point :) But it's also easy to abuse newer syntax - "newer must mean better" rather than "oh, here's an addition that maybe is cleaner in some cases". Do what works for you if you're the only person likely to look at the code later. If others may need to support it later, you may have to think a little harder about how to write - readability is not a binary choice. > Of course I considered the use of a function where I passed the required > parameters. But the issue is the access to the data - that getDataSet() > was a performance hit when I used a passed parameter. I could have > opened/accessed/retrieve the data during the opening but thought it best > to use a lazy data access as needed. > > Today was not really about performance but more about learning to use > the comprehension. You see I did attempt to do create the > comprehension. But after seeing your code I realized that I had the '[' > and the '{' confused. I believed I had to use '{'. I just reviewed a > tutorial off the net and that was what they were using. With curly braces it would be a dictionary comprehension. I just remembered I once saw a tutorial that I thought did a pretty nice job on comprehensions, and I had saved the link, again it's down to personal taste but take a gander at this to see if it makes sense: https://treyhunner.com/2015/12/python-list-comprehensions-now-in-color/ _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor