Python Forum
A deciphering problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A deciphering problem
#21
@DPaul You get an error with my code?
What is the actual traceback error to see what line is throwing the error?
What version of python are you using? I'm on 3.9.4

If you are not on version 3.9
Add the import
from typing import List
and change list on line 38
@dataclass
class CipherLine:
    line: str
    cipher_data_possibilites: list[CipherData]
to List
@dataclass
class CipherLine:
    line: str
    cipher_data_possibilites: List[CipherData]
Reply
#22
(Aug-23-2021, 04:00 PM)DPaul Wrote: I would like to study Yoriz' solution too,
but both version 1 and 2 give a "TypeError: 'type' object is not subscriptable".
Do you get it working?
Yes, I had the same error but I've got it working now. I had to upgrade from Python 3.8 to 3.9.5. Now it works.
(The first time I just removed the type hints. Smile )

Ivo.
Reply
#23
@ Yoriz

I'm also on 3.8.x.
I'm a little confused as to the line numbers you propose to change....
This is the error message.
Thanks for your help.
Paul
Output:
Traceback (most recent call last): File "K:\zztemp1\testpy.py", line 27, in <module> class CipherLine: File "K:\zztemp1\testpy.py", line 29, in CipherLine cipher_data_possibilites: list[CipherData] TypeError: 'type' object is not subscriptable
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#24
@DPaul I edited my code in the previous posts so the code there will work with python version 3.8 or you can just remove the type hints like @ibreeden did, if you are not a fan of them.
Reply
#25
OK, works perfectly.
It allowed me to discover some python features I had not encountered before.
In fact you generate the 66 possible shifts and then sum the blanks and the letters contained in 'aeiou',
and you take the one with the best score. Nice.
I did some "sensitivity analysis" and it would seem the presence of blanks is more crucial than the letters.
(e,t,a) are the most used letters in English, the system even works with "e" alone. (But e.g. not with only 'y')
Good show.
Yoriz likes this post
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#26
Thank you @Yoriz ,
I learned a lot about type hints. They are very useful.
Yoriz likes this post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020