JacobTomaw

JacobTomaw

Python Brain Teasers: Teaser 3 wrong answer

For every minor version of Python 3 I can run the code against quickly this code prints 6.

❯ for minor in `seq 2 8`; do; echo "Python 3.$minor"
docker run -it python:3.$minor python -c "print(len('Kraków'))"
done
Python 3.2
6
Python 3.3
6
Python 3.4
6
Python 3.5
6
Python 3.6
6
Python 3.7
6
Python 3.8
6

Python 2.7 the answer is 7.
Am I doing something unexpected?

Most Liked

JacobTomaw

JacobTomaw

I did not doubt that you have tested the code.
Your file definitely has different chars in it. Below the file /tmp/krakow has your string on the first line and mine that I typed on my Mac. Yours is o + Combining Acute Accent and mine is Latin Small Letter O with Acute. If I needed to I am sure I could figure out how to type combining acute accent, but when working through the book and seeing a char i can type with two keystrokes on my mac (option + e, o) I am going to do that. It might be valuable to note this in the book in someway.

❯ more /tmp/krakow
Kraków
Kraków

❯ xxd -b -c9 /tmp/krakow
00000000: 01001011 01110010 01100001 01101011 01101111 11001100 10000001 01110111 00001010  Krako..w.
00000009: 01001011 01110010 01100001 01101011 11000011 10110011 01110111 00001010           Krak..w.

❯ xxd  -c9 /tmp/krakow
00000000: 4b72 616b 6fcc 8177 0a  Krako..w.
00000009: 4b72 616b c3b3 770a     Krak..w.
tebeka

tebeka

Author of Go Brain Teasers

Hi @JacobTomaw. It’s probably a problem in the encoding of the PDF (trust me, I tried :slight_smile: )
Take a look at the code in https://github.com/tebeka/python-brain-teasers and let me know if you have an issue - it prints 7 for me:

$ python --version
Python 3.8.3
$ python city.py  
7
tebeka

tebeka

Author of Go Brain Teasers

I do doubt myself :slight_smile:

I’ll think how to clarify this in the book. Thanks!

Where Next?

Popular Pragmatic Bookshelf topics Top

johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
edruder
I thought that there might be interest in using the book with Rails 6.1 and Ruby 2.7.2. I’ll note what I needed to do differently here. ...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New

Other popular topics Top

DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
New

Sub Categories: