• Clay_pidgin@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    5
    ·
    2 days ago

    foo = “potatoes!”

    len(foo)

    will give you the number of characters in the string. It’s not a surefire way to find a list at all!

    • sugar_in_your_tea@sh.itjust.works
      link
      fedilink
      arrow-up
      3
      ·
      2 days ago

      Same with dictionaries, iterators (will consume the iterator!), and anything else that has a length.

      I’ve actually had the string instead of list issue a number of times, because sometimes things get off and it’s hard to track down where things went wrong.

      For this reason, I think type hints are the way to go. Use them consistently w/ a static analysis tool like pyright and you’ll catch a lot of these issues before running into cryptic error messages.