You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def contains_magic_number(list, magic_number):
for i in list:
:-)
CastixGitHub
changed the title
paragraph 1.6 does not respect 1.3
built-in overriden in "correctness -> else clause on loop without a break statement"
Jan 6, 2018
Talking about correctness, instead of break, I think return is more appropriate here
>>>defcontains_magic_number(numbers, magic_number):
... forninnumbers:
... ifmagic_number==n:
... returnTrue
... else:
... returnFalse
...
>>>print("This list contains the magic number."
... ifcontains_magic_number(range(10), 5)
... else"This list does NOT contain the magic number.")
Thislistcontainsthemagicnumber
otherwise do not use a loop at all, use a list comprehension or filter() instead
>>>defcontains_magic_number(numbers, magic_number):
... iflen([nforninnumbersifn==magic_number]) !=0:
... print("This list contains the magic number.")
... else:
... print("This list does NOT contain the magic number.")
...
>>>contains_magic_number(range(10), 5)
Thislistcontainsthemagicnumber.
The list built-in is overridden
Thanks for your beautiful work :)
The text was updated successfully, but these errors were encountered: