I have an example array like:
array = [1, 2, 3, 4, 5, 6]
Every of this numbers refers to an object that has text property. I want to make sure that every of these object has the same text value. Currently I do it like this:
correct = []
for number in array:
if(object[number].text == "Sample"):
correct.append(number)
if correct.length == array.length:
return True
Is there a more efficient way to do this, like with lambda function or?
return false
in your code for example) \$\endgroup\$text != "Sample"
and returning false would avoid the need to create and append a collection, then just return true if you make it out of the loop. \$\endgroup\$