What if I want to count a item which start with a character in a list?
Hello @konojames5808740993. You could use regular expressions, or you could loop through the list, append any item that starts with a certain character to a new list, then count the number of items in that list:
org_list = ["abc", "abd", "ad", "da"]#The original list #counting items that start with "a" new_lst = #defines the new list with which to append the items def count_items():#defines the function for i in org_list:#loops through the original list if i == "a":#checks to see if the first character of the item i in #the original list matches the character you want new_lst.append(i)#if the above is the case, it appends that item to #the new_lst return len(new_lst)#this returns the length of the new list-the same as #counting how many items there are in a list beginning with a certain character
I hope this helps!