rlvaugh / impractical_python_projects Goto Github PK
View Code? Open in Web Editor NEWCode & supporting files for chapters in book
Code & supporting files for chapters in book
Couldn't figure out any other way to communicate, but I'm enjoying your IPP book. I'm wondering how you'd feel if I used the book as a basis for a series of blog posts in Haskell; i.e, project translation? It's getting me a bit depressed about state of our ecosystem; for Monte Carlo, for instance, I'm working the "user-friendly" monomer framework, but monomer is buggy, questionably documented, and "user-friendly" is relative.
Hi there,
Ive had fun running through this book. Already have Real World Python and cant wait to dive into it also...
Unfortunately with the Monty Hall Game exercise, I keep getting the same error. Ive copy and pasted your version to make sure I wasnt missing a typebo or something. All files were downloaded and in the same folder as the code for the game. Im using Spyder IDE (via Anaconda) and Mac OS.
error reads:
runfile('/Users/+++++/Monty Hall Game/monty_hall_gui.py', wdir='/Users/+++++/PythonPractice/Monty Hall Game')
Traceback (most recent call last):
File "/Users/+++++/Monty Hall Game/monty_hall_gui.py", line 172, in
game = Game(root)
File "/Users/+++++/PythonPractice/Monty Hall Game/monty_hall_gui.py", line 26, in init
self.create_widgets()
File "/Users/+++++/PythonPractice/Monty Hall Game/monty_hall_gui.py", line 32, in create_widgets
self.photo_lbl = tk.Label(self.parent, image=img,
File "/opt/anaconda3/lib/python3.8/tkinter/init.py", line 3143, in init
Widget.init(self, master, 'label', cnf, kw)
File "/opt/anaconda3/lib/python3.8/tkinter/init.py", line 2567, in init
self.tk.call(
Any help is greatly appreciated. Thanks for the good read!!
where can i get the file 2of4brif.txt? its referenced in various programs, but not included in the source, as far as I can see.
The script doesn't work as intended if two single letter words (except 'a' and 'i') are consecutive in the list/dictionary file.
I enteredcode from book. When I ran the code..I got "MemoryError"
while processing the
green_data.appendlist(image.getdata(1)))
so I copied the code from the github file
got same error with the blue_data.append ...line.
looked for a n errata for pg.338 but found none.
??
@rlvaugh this book is great! Really enjoying it!
It looks like find_anagrams() is only able to produce anagrams composed of unique letters (i.e. n letters with n distinct letters).
For example, my name is david. When I run this function the word "dad" is not returned as a possible anagram. I believe this is because of line 28-31 (below):
for letter in word:
if word_letter_map[letter] <= name_letter_map[letter]:
test += letter
if Counter(test) == word_letter_map:
anagrams.append(word)
The test string only receives a singular letter, rather than the value attached to the letter, making it impossible to have an anagram where a single letter appears more than once in the word. Once we get to the second if statement, we only have a string (test) comprised of letters that all have a frequency of 1, limiting the words we can utilize.
Was this an intentional decision or am I possibly misinterpreting something?
I updated the function with the following logic (seems to work, but curious if you see an error):
for letter in word:
if word_letter_map[letter] <= name_letter_map[letter]:
test += letter*word_letter_map[letter]
if Counter(test) == word_letter_map:
anagrams.append(word)
Now it will add a letter to the string 'test', but will add that letter * the number of times it exists in the word of interest. On some basic testing it seems to work, but I am curious if I am overlooking something here. Do you think this is a good modification?
I noticed that when working with a ciphertext of odd numbers we receive an error with the rail_fence_cipher_decrypt.py file. I copied your code from this github, but could be missing something.
For a reproducible example you could update line 22 to:
ciphertext = HLOEL
Running rail_fence_cipher_decrypt.py should output Hello
but instead we get an error due to attempting touse .lower() on a NoneType
object (due to the itertools.zip_longest adding a None in the odd situation).
Do you get the same error? I am guessing a solution could be to add some logic to skip past Nonetype.
I put together a little solution that is working, but would be curious of a better approach. Overview: If r2 is None, then I overwrite the value with a letter and also update variable "odd" to be True. Then, changed your logic test to be a test where if odd = true then run the .pop() on the plaintext to remove the arbitrary letter.
This allows me to get a plaintext output of Hello
, but again curious if there are better approaches! Still loving the book, had to slow down a bit due to work but learning a bunch!
In the line prefaced by bullet-point number 7, it reads:
next_try[lock_wheel] = randint(0, len(combo) - 1)
which means that we try a digit on that index that depends on the combination length, instead of just picking a digit from 0 to 9.
It works in the example, since the combination is 10 digits long, so that the line evaluates to randint(0, 10 - 1)
.
However, it fails to solve all combinations where
any([digit > len(combo) - 1 for digit in combo])
holds true, e.g. an 8 occurs in a combination of length 5.
While writing this, I noticed the issue is fixed here.
I am leaving this issue for others to find and as a reminder that this should be corrected in future print versions.
Firstly, great hidden message :)
When working through this I got a bit stuck on the example message provided so wanted to share that feedback.
Example provided:
The cold tea didn't please the old finicky woman
Output: H-E-L-L-O
You stated this would be an example of input = 2, so from this I assumed that we should just always start with the first word in a sentence and take the nth character, then increment by the input to the next nth word and take the nth character.
In the actual hidden message you have to increment by the input from the beginning in order to properly solve, which changed my underlying function. This would also mean the above example would look like this:
The cold tea didn't please the old finicky woma.
Output: O-I-H-I (almost my home state!)
Maybe I missed something here, but wanted to point it out as it threw me off a bit in solving for the colchester_msg.txt file.
Thanks, really enjoying these problems! It is a great book!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.