0

I want to write a loop function which returns True if all the element equals to 3, and return False otherwise. WITHOUT using the abstract function.

is_same([3,3,3,3,3]) => True
is_same([3,4,6]) => False
3
  • which abstract function is this? i know of no such thing in the standard library Commented Nov 11, 2019 at 16:23
  • well, idk which abstract function you're talking about but all those 3 solutions will work : all(x==3 for x in your_list), len(filter(lambda x: x!=3, your_list)) == 0, len(set(your_list)) == 1 and your_list[0] == 3 Commented Nov 11, 2019 at 16:29
  • Abstract function means filter, map Commented Nov 11, 2019 at 17:30

1 Answer 1

2

This could work:

all(x == 3 for x in myList)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.