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?

3 Likes

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
2 Likes

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.
3 Likes

I do doubt myself :slight_smile:

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

2 Likes