-1

I use the method split() of the string class and supposedly it returns a list, but it isn't a common list because I can't use list methods like count()

I've tried to use the count method of list but it doesn't work.

def do_prueba(self, s):

    lista=s.split()
    len=lista.count()
    print(len)

I want to know the length of that list. I'm new to Python sorry.

Pynchia
  • 10,996
  • 5
  • 34
  • 43
  • 3
    You are confusing what `count` does. `mylist.count(x)` returns the number of occurences of `x` in the list `mylist`. What you want is `len`. – busybear Feb 05 '19 at 03:50

1 Answers1

2

You aren't providing an argument to count. Just use the len function to get the length (not to be confused with the variable you named len, which you shouldn't do as it overrides the built-in):

def do_prueba(self, s):
    lista=s.split()
    print(len(lista))
iz_
  • 15,923
  • 3
  • 25
  • 40