First of all, you have a syntax error:
It should be elif x == 6:
as =
is the assignment operator and ==
is the comparison operator, and you are trying to compare, not assign.
Next, you need to put the for
loop inside a function in order to return
a value. return
can only be used inside a function. Otherwise, it returns a syntax error. So, make a function and insert the for
loop inside it like this:
def function (y):
for x in y:
if x in {3,4,6}:
return (x)
else:
return ('not found')
Then, you need to call the function on y
. Like this:
function(y)
It is unclear what you mean by "handle all of such returned data at once as list". Anyway, if you mean that you want to store all the returned data in a list, then create an empty list and append each return value of function
to the empty list. Like this:
def function (y):
emptyList = []
for x in y:
if x in {3,4,6}:
emptyList.append(x)
else:
emptyList.append("not found")
return emptyList
If you could provide a more clear question, I'll edit to fit your needs!