Ad
  • Default User Avatar

    It's not optimal, you are right! But actually, it only needs to iterate through the list 4 times. The len() method in python does not need to iterate through the array to find the length, but python caches the length in an attribute!