#pythonquestion — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #pythonquestion, aggregated by home.social.
-
Python Question: Is there an efficient way to see if every element in an iterable is equal to a user-specified value?
The best idea I've seen so far is to use a list comprehension to check for equality, and then use the all function, like this:
MyList = [1,1,1,1,1,1,1]
all((x==1 for x in MyList))That's readable and probably not bad performance. Is there something better?
-
Python Question: Is there an efficient way to see if every element in an iterable is equal to a user-specified value?
The best idea I've seen so far is to use a list comprehension to check for equality, and then use the all function, like this:
MyList = [1,1,1,1,1,1,1]
all((x==1 for x in MyList))That's readable and probably not bad performance. Is there something better?
-
Python Question: Is there an efficient way to see if every element in an iterable is equal to a user-specified value?
The best idea I've seen so far is to use a list comprehension to check for equality, and then use the all function, like this:
MyList = [1,1,1,1,1,1,1]
all((x==1 for x in MyList))That's readable and probably not bad performance. Is there something better?
-
Python Question: Is there an efficient way to see if every element in an iterable is equal to a user-specified value?
The best idea I've seen so far is to use a list comprehension to check for equality, and then use the all function, like this:
MyList = [1,1,1,1,1,1,1]
all((x==1 for x in MyList))That's readable and probably not bad performance. Is there something better?
-
Python quiz
What is the result
A. Invalid syntax, should use 'if' for condition
B. [80,73,82,64]
C. [True, True, True, True, False]
D. [80] -
Python quiz
What is the result
A. Invalid syntax, should use 'if' for condition
B. [80,73,82,64]
C. [True, True, True, True, False]
D. [80] -
Python quiz
What is the result
A. Invalid syntax, should use 'if' for condition
B. [80,73,82,64]
C. [True, True, True, True, False]
D. [80] -
Python quiz
What is the result
A. Invalid syntax, should use 'if' for condition
B. [80,73,82,64]
C. [True, True, True, True, False]
D. [80] -
-
-
-