New course! Every coder should learn Generative AI!
Try a free lesson+ 5
y= [x if x==1 else x*2 for x in ["1","2"]]
print(y)
Let me break this down for you:
y=x if x==1 //not true
else:
y=x*2 for x in ["1","2"]
Each element in ["1","2"] is multiplied by two //"for x in"
Final result [11,22]