Post Reply 
Little explorations with HP calculators (no Prime)
12-27-2018, 11:58 PM
Post: #324
RE: Little explorations with HP calculators (no Prime)
(12-27-2018 10:20 PM)Thomas Klemm Wrote:  The function match_count uses generator expressions.
And since random.shuffle shuffles in place we can reuse thelist.
You can use enumerate to iterate over a list when both index and value are needed.

Hi Thomas -

Thanks for the reminders (and great examples) about using generator expressions and enumerate. I've used both of those before in sample exercises I've worked through, but obviously haven't adopted them into my python code-building thoughts yet. Practice, practice, practice.

I'll need more time to analyze your implementation of match_count, though, as its use of the "blue" variable is puzzling me. Your code clearly works, though, so I'm sure you've crafted it carefully (as you always do).

Despite your code being much more compact, it was a bit slower on my laptop (506 seconds vs. 483 seconds for my original version). I may try some additional runs to see how much variance there is in both versions' run times. I'm wondering if garbage collection can account for at least part of the difference.

Thanks for doing this -- it's a great help in my learning process!
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: Little explorations with HP calculators (no Prime) - DavidM - 12-27-2018 11:58 PM

User(s) browsing this thread: 1 Guest(s)