Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
help with type hints
-
When I use type hints like this
def average_streak_len(streak_history: dict [str, str]): # Create a dictionary to store the most common value for each team average_streaks = {} # Iterate through each key-value pair in the input dictionary for team, value_list in streak_history.items(): # Count the occurrences of each value in the value_list value_count = {} for value in value_list: value_count[value] = value_count.get(value, 0) + 1 # Find the value with the maximum count for this team max_value = max(value_count, key=value_count.get) # Store the most common value for this team average_streaks[team] = max_value return average_streaks
I get an error that says
TypeError: 'type' object is not subscriptable
why is this?
-
@resserone13v2-0 Do you use the last version of Pythonista because the syntax you use needs Python >= 3.9
See here
-
@cvp OK. I will give this a read through and check which version of python I'm running.. thanks
-
@cvp I think I'm running 3.11.
I typed python -v in the cmd line
printed this
\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_ -
@resserone13v2-0 said
I typed python -v in the cmd line
I think you are not in Pythonista. There is no command line and this command is not accepted in console line.
Are you on a PC or a MAC ?And if I try your script, I don't get an error in Pythonista 3.4 which runs Python 3.10
-
@cvp pc my IDE is spyder. Maybe its the version that spyder is running. No worries. Not a big deal. Ive just been working on making my code more clean. Im sure ill figure it out and the code is doing what i need it to. There is a lot to learn. Not just a language but installing packages running different versions of a language. Storing files. For me its good cuz there is always something new to learn
-
@resserone13v2-0 understood but this is a Pythonista forum....
-
@cvp ok. Ill keep make sure all my post are pythonista related.
-
@resserone13v2-0 you can always search stack overflow for your error
There are a few workarounds depending on the version you are using.
-
@JonB exactly the link I mentioned in my first post