+ 2

How do I print the following on Python?

Suppose I made a list : [ā€˜appleā€™ , ā€˜orangeā€™ , ā€˜pear , ā€˜kiwiā€™] And I went through a filtering process in a for loop Which filtered ā€˜appleā€™ and ā€˜kiwiā€™ out. I would like the result to be: apple and kiwi chosen But i donā€™t know how to add the ā€˜andā€™ between two items from the list and printing them individually, with the ā€˜chosenā€™ at the end. Plus, the result would be diferrent everytime e.g if only orange is chosen, itā€™ll print: orange chosen Thanks!

1st Oct 2019, 9:32 AM
SquareGrids
SquareGrids - avatar
1 Answer
+ 6
Why not select Apple and Kiwi into a new list called k? Then, you can do: print(*k, sep=" and ", end="chosen.")
1st Oct 2019, 9:55 AM
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬ - avatar