0

Say I have this list: list = ["Coin", "Stick", "Coin"] I want to check if the list contains n amount of coins. What is the simplest method of doing this, without changing the original list?

I have tried if ["Coin", "Coin"] in list but that only works if the coins are next to each other.

Help pls
  • 19
  • 5

1 Answers1

3

Use the count method:

items = ["Coin", "Stick", "Coin"]
print(2 == items.count("Coin"))
Tomer Ariel
  • 1,397
  • 5
  • 9