Finding Index positions in Lists and counting duplicates

Finding Index positions

my_list = ['a', 'b', 'c', 'd']

idx_pos = my_list.index('a') # This will print the index position. I.e 2
# The variable will return an INT

Counting duplicates

my_list = ['a', 'b', 'c', 'd', 'c', 'c']
c_count = my_list.count('c') # The variable will return an INT

NOTE:

  • Any SLICING that you do with a LIST returns a LIST

  • Any SLICING that you do with a TUPLE returns a TUPLE

Last updated