Want to count the occurences of an element in a list?

Submitted 3 years, 6 months ago
Ticket #184
Views 246
Language/Framework Python
Priority Low
Status Closed

Please tell a way......

Submitted on Oct 01, 20
add a comment

1 Answer

Verified

Use len(list) function.

In [1]: l = (1, 2, 3)

In [2]: len(l)
Out[2]: 3

Update:

In [14]: l = (1, 3, 4, 5, 4, 3, 4)

In [15]: {x: l.count(x) for x in set(l)}
Out[15]: {1: 1, 3: 2, 4: 3, 5: 1}

Submitted 3 years, 6 months ago

It is not about length of list , I want to know how many times a element is repeated in the list...but tq for your response

- Soudhamini 3 years, 6 months ago

check my update

- nikita 3 years, 6 months ago

yes it is correct .Thank you for your answer

- Soudhamini 3 years, 6 months ago


Latest Blogs