Why doesn't the code below produce any output?
Solution 1:
welcome Nicathus !
That's because x is a list that contains one string. But x is not a string itself.
So :
-
in the first case, i takes the value of each item in this list (as this list's length = 1 , the loop will be quickly done). So when i is the item "Decomplete asd", which is a string, the conditions are true : "De" and "comp" are in this string.
-
in the second case, the conditions apply directly to x. And x is a list, not a string. It means that you're looking for the strings "De" and "comp" in a list that does not contain them, as items.
It would work if you had x = ["De", "comp", "hello"]
for instance.
Or if you had x = "Decomplete asd"
(i.e. a string, without [
and ]
).
Hope it helped !