+ 2
How can I print a Python set so it looks clean (no {} brackets or quotes)?
Hey! I’m working with a set in Python like this: >> fruits = {"apple", "banana", "mango"} However, whenever I print it, curly brackets and quotes appear around the words. I want the output to look like this (just plain words): apple banana mango What’s the simplest way to do this? (Bonus: What if my set contains numbers instead of strings?)
2 Respostas
+ 3
Use the unpacking operator:
print(*fruits)
What output do you want to achieve for numbers?
0
You can use "join".
fruits = sorted(fruits, key=None, reverse=False)
fruits = ' '.join(fruits)
print(fruits)
https://www.sololearn.com/ru/compiler-playground/cmmPWZygqs4i/?ref=app