+ 23

Sets python

Is it possible to print a set in an easy way without brackets & double quotes. I'm seeing a lot of YouTube videos but all of them end up at creating a class and object to do that. Any idea of how to do that. Please no hate comments!

14th Apr 2021, 7:20 PM
Veena Tirmal
Veena Tirmal - avatar
22 Answers
+ 15
A set is a iterable so we can use the iterable unpacking operator (*) Example: >>> a={1,2,3,4} >>> print(*a) 3 2 1 4
18th Apr 2021, 7:11 AM
Levi
Levi - avatar
+ 4
Help in the Variables in Python
23rd Nov 2021, 5:57 AM
Shubham Bhatia
Shubham Bhatia - avatar
+ 1
sets1 = {1,2,3,4,5} print(*sets1) --> 1,2,3,4,5 sets2 = {'a','b','c','d','e'} print(*sets2) --> a b c d e
27th May 2022, 7:32 AM
Surya S
Surya S - avatar
+ 1
set1 = {2, 4, 5, 6} set2 = {4, 6, 7, 8, 11, 42, 2} #your code goes here if __name__ == '__main__': set1 = [2,4,5,6] set2 = [4,6,7,8,11,42,2] common = set(set1).intersection(set2) print(common) #its works for me ;)
25th Dec 2022, 7:11 PM
Jonathan Zapata
0
Or in python: st = {1,2,2,3,3,4,5,6} #1. print(' '.join([str(m) for m in st])) #2. for m in st: print(m, end=' ') #Both 1 and 2 will print 1 2 3 4 5
14th Apr 2021, 7:59 PM
G B
G B - avatar
0
thisset = {"apple", "banana", "cherry"} for i in thisset: print(i) Try this. Easy way to do that
12th May 2021, 4:53 AM
Pulkit Saini
Pulkit Saini - avatar
0
Python code : s={8, 2,3,1,4} [print(s, end= " " ) for I in s] [cout << " hello World "] ; Type in the Notepad 📒with extesion (main.py)
23rd Nov 2021, 8:17 AM
Shubham Bhatia
Shubham Bhatia - avatar
0
A scripting language is a programming language that is interpreted. It is translated into machine code when the code is run, rather than beforehand. Scripting languages are often used for short scripts over full computer programs. JavaScript, Python, and Ruby are all examples of scripting languages.
1st Feb 2022, 7:39 AM
Abraham Zimba
Abraham Zimba - avatar
0
I need some mentor here. Who can volunteer to join our whatsapp group and assist to coach people on Python with me as I am not always online and questions that need are popping in. Here is the group link https://chat.whatsapp.com/FZ25xgrgrnVGGap0cxIlHD The more you teach the more you learn. That is just a fact!
10th Mar 2022, 12:00 PM
DN Josh 🇳🇬
DN Josh 🇳🇬 - avatar
0
Hello can anyone help me with coding I'm new
13th Mar 2022, 9:46 AM
Six Gang
0
Hey can I have some help with this I'm kinda new to this app
8th May 2022, 10:06 PM
Crystal Banyard
0
For I in range(10): printf("sorry my friend!")
15th Oct 2022, 5:37 AM
AHMAD MUSA WAZIRI
AHMAD MUSA WAZIRI - avatar
0
print (set1 & set2)
22nd Nov 2022, 4:00 PM
Sidhartha rao Adike
Sidhartha rao Adike - avatar
0
sets1 = {2,4,5,6} sets2 = {4,6,7,8,11,42,2} print(sets1 & sets2)
31st Jan 2023, 4:35 PM
Ainur Akhmet-Ganiyeva
Ainur Akhmet-Ganiyeva - avatar
- 1
Totalnumbers=int(input()) x=[] for i in range(Totalnumbers): Numbers=int(input()) x.append(Numbers) z=0 y=0 while z<Totalnumbers: z=+1 if x[y]>x[z]: x[y],x[z]=x[z],x[y] y=+1 Totalnumbers=-1 print(x[Totalnumbers]) No output
16th Jan 2022, 12:00 AM
Manal Boussalam
- 1
Sets python Is it possible to print a set in an easy way without brackets & double quotes. I'm seeing a lot of YouTube videos but all of them end up at creating a class and object to do that. Any idea of how to do that. Please no hate comments!
4th Apr 2022, 6:00 PM
AHMAD MUSA WAZIRI
AHMAD MUSA WAZIRI - avatar
- 2
I do it this way: var a:Set<Int> = setOf(1,2,3) a.forEach { print("$it ")} // will print: 1 2 3
14th Apr 2021, 7:41 PM
Coding Cat
Coding Cat - avatar
- 2
That just the logic curly braces must be use, else that's not a Set.
16th Apr 2021, 8:52 AM
UGOBEST
UGOBEST - avatar
- 2
Guys can anyone help me who to code in python culcaulan
6th Jul 2021, 12:24 PM
Prakash Joshi