G+_Brandon Ingli Posted April 26, 2014 Share Posted April 26, 2014 Using two input text files and the latest prize data from powerball.com, I threw together a script to check powerball tickets! Just put the three files in the same directory and it works fine Proper formats of the files are in the comments of the script. Enjoy and love the show! UPDATE: Updated code to use for loops and lists over repetitive variables! Thanks commenters! https://github.com/mrbmi513/c101/tree/master/powerball%20checker Link to comment Share on other sites More sharing options...
G+_L I Posted April 27, 2014 Share Posted April 27, 2014 I was reading up on some more cool (and powerful) Python constructs such as list comprehension and sets and decided to try to modify this code to implement it. http://pastebin.com/iWGNggy3 Link to comment Share on other sites More sharing options...
G+_Brandon Ingli Posted April 27, 2014 Author Share Posted April 27, 2014 Lionel D great, but what about the multiple ticket entries I coded for? Link to comment Share on other sites More sharing options...
G+_L I Posted April 27, 2014 Share Posted April 27, 2014 It does that too. I knew there has to be a way to do it. I saw some things like maps and lamdas and zips that maybe others can comment on. But I finally found the nested comprehension syntax at Stack Overflow and it works like a charm. It's the line that says: your_tickets = [[int(num) for num in ticket.split(",") if num.isdigit()] for ticket in initial_your_numbers.split( ';')] I still have to get my head around it to read it. The format for a single list is: [item1/function on item1 for item1 in list1 if condition] It's a way to mash three or four lines of code into one and let's you substitute ... so that your item1/function could a nested list comprehension like in the case of the tickets! Now I see why Python is so popular. Link to comment Share on other sites More sharing options...
G+_L I Posted April 27, 2014 Share Posted April 27, 2014 I hope that makes some sense Link to comment Share on other sites More sharing options...
G+_Brandon Ingli Posted April 27, 2014 Author Share Posted April 27, 2014 Lionel D a bit too complex for even me let alone viewers of the podcast. Link to comment Share on other sites More sharing options...
G+_L I Posted April 27, 2014 Share Posted April 27, 2014 Hmmm it was certainly a brain fryer - like the first time I saw Inception. Let me try again without all the fancy stuff. I was trying to reduce some of the repetitive code by moving more things into for loops. Link to comment Share on other sites More sharing options...
G+_L I Posted April 27, 2014 Share Posted April 27, 2014 I started looking at the my1 my2 my3/win1 win2 variables as a perfect candidate for a list and that would reduce the multiple if statements both inside the try blocks and when checking for the winning numbers. Link to comment Share on other sites More sharing options...
G+_Lee Crocker Posted April 29, 2014 Share Posted April 29, 2014 Yeah, lots of repetition. Anytime you start to use variables like win1, win2, win3, you should immediately start thinking of coverting to a list (or dictionary or set). Not only will it make the code simpler and more efficient, but also easier to change and adapt to different sizes.? Link to comment Share on other sites More sharing options...
G+_Brandon Ingli Posted April 30, 2014 Author Share Posted April 30, 2014 I see what you mean Lee Crocker I should be able to add that to the code by Thursday's Episode! Link to comment Share on other sites More sharing options...
G+_Brandon Ingli Posted April 30, 2014 Author Share Posted April 30, 2014 I updated the code. Same link works. Let me know your comments! Link to comment Share on other sites More sharing options...
Recommended Posts