omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    3
    10
    224
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      resserone13v2.0 last edited by resserone13v2.0

      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?

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @resserone13v2.0 last edited by

        @resserone13v2-0 Do you use the last version of Pythonista because the syntax you use needs Python >= 3.9

        See here

        R 2 Replies Last reply Reply Quote 0
        • R
          resserone13v2.0 @cvp last edited by

          @cvp OK. I will give this a read through and check which version of python I'm running.. thanks

          1 Reply Last reply Reply Quote 0
          • R
            resserone13v2.0 @cvp last edited by

            @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_

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @resserone13v2.0 last edited by cvp

              @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

              R 1 Reply Last reply Reply Quote 0
              • R
                resserone13v2.0 @cvp last edited by

                @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

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @resserone13v2.0 last edited by

                  @resserone13v2-0 understood but this is a Pythonista forum....

                  R 1 Reply Last reply Reply Quote 0
                  • R
                    resserone13v2.0 @cvp last edited by

                    @cvp ok. Ill keep make sure all my post are pythonista related.

                    JonB 1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB @resserone13v2.0 last edited by

                      @resserone13v2-0 you can always search stack overflow for your error

                      https://stackoverflow.com/questions/63460126/typeerror-type-object-is-not-subscriptable-in-a-function-signature

                      There are a few workarounds depending on the version you are using.

                      cvp 1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @JonB last edited by

                        @JonB exactly the link I mentioned in my first post

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors