Skip to content

Instantly share code, notes, and snippets.

@ioanzicu
Created July 28, 2022 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioanzicu/ec3c915207a76800546a85cd8dfc0f19 to your computer and use it in GitHub Desktop.
Save ioanzicu/ec3c915207a76800546a85cd8dfc0f19 to your computer and use it in GitHub Desktop.
Count items in a list recursive in Python 3
def count(items):
if not items:
return 0
return 1 + count(items[1:])
nums = [0, 1, 5, 9, 22, 33, 44, 88, 333, 555, 666, 999]
result = count(nums)
print(result)
print(len(nums))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment