The process for counting sequences in Python depends on the type of sequence you want to count. Here are some examples:
my_list = [1, 2, 3, 4, 5]
count = len(my_list)
print(count) # Output: 5
my_string = "hello world"
count = len(my_string)
print(count) # Output: 11
my_list = [1, 2, 3, 4, 5, 2, 2]
count = my_list.count(2)
print(count) # Output: 3
my_string = "hello world"
count = my_string.count("o")
print(count) # Output: 2
my_list = [1, 2, 3, 4, 5, 1, 2, 3]
count = len(set(my_list))
print(count) # Output: 5
Asked: 2023-06-10 10:53:17 +0000
Seen: 14 times
Last updated: Jun 10 '23