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

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=> (create-migration "guestbook") Execution error (Ill...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New
Fl4m3Ph03n1x
Background Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New

Sub Categories: