0
Обясните пожалуйста
fruits=["apple","banana","cherry","kiwi","mango"] newlist=[] for x in fruits: if "a" in x: newlist.append(x) print(newlist)
2 Antworten
+ 1
Its as simple as it appears.
You have 2 baskets one with some fruits in it, and another is empty.(line 1,2)
Now from available fruits in basket 1 your are picking a fruit one by one.(line 3)
Now you are checking if there is an "a" in the fruit name. If yes then you put that fruit in blank basket.(line 4,5)
At the end you are showing your basket with fruits with "a" in their name.
+ 1
thank you very much