user584694 user584694 - 1 year ago 58
Python Question

Get the number of same string in a list

I want to get the no. of same string in a list


list = ['jack','jeen','jeen']
number_of_jeen = getnumber('jeen',list)



I have tried this so far

def getnumber(string_var,list):
if any(string_var in s for s in list):
print("This user exits !")

Answer Source

There's a built-in method count that does this.

number_of_jeen = list.count('jeen')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download