+ 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!
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
+ 4
Help in the Variables in Python
+ 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
+ 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 ;)
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
0
thisset = {"apple", "banana", "cherry"}
for i in thisset:
print(i)
Try this. Easy way to do that
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)
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.
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!
0
Hello can anyone help me with coding I'm new
0
Hey can I have some help with this I'm kinda new to this app
0
https://www.sololearn.com/discuss/3036158/?ref=app
https://www.sololearn.com/discuss/3035887/?ref=app
https://www.sololearn.com/discuss/3035548/?ref=app
https://www.sololearn.com/discuss/3035610/?ref=app
https://www.sololearn.com/discuss/3035739/?ref=app
https://www.sololearn.com/discuss/3035624/?ref=app
https://www.sololearn.com/discuss/3035752/?ref=app
https://www.sololearn.com/discuss/3036009/?ref=app
https://www.sololearn.com/discuss/3035538/?ref=app
https://www.sololearn.com/discuss/3035824/?ref=app
0
For I in range(10):
printf("sorry my friend!")
0
print (set1 & set2)
0
sets1 = {2,4,5,6}
sets2 = {4,6,7,8,11,42,2}
print(sets1 & sets2)
- 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
- 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!
- 2
I do it this way:
var a:Set<Int> = setOf(1,2,3)
a.forEach { print("$it ")}
// will print: 1 2 3
- 2
That just the logic curly braces must be use, else that's not a Set.
- 2
Guys can anyone help me who to code in python culcaulan