+ 1
How can I make this code more pythonic ?
7 Respuestas
+ 2
a=[2,4,8,16,32,64]
b=[4,8,12,16,20,24,32,40,64]
c=[8,16,24,32,40,64,80]
d={}
for i in a+b+c:
if i in d:
d[i]+=1
else:
d[i]=1
for i in d:
if d[i]==3:
print(i)
#2nd way
d= a +b+c
for i in d :
if d.count(i) >= 3 :
print(i)
d.remove(i)
Edit:
I think, you mean s implication, or other alternatives...
+ 2
Ishan .sort_index()
The dict was already sorted, I added it to the list. It should sort every time
+ 1
I would try using Pandas, I believe the output is the same
https://code.sololearn.com/ck0G7w9z3PUX/#py
+ 1
Steven M what can be done to maintain order ? thnx for ur code ..
+ 1
Desired output can be achieved with list only.
pls find the code.
a=[2,4,8,16,32,64]
b=[4,8,12,16,20,24,32,40,64]
c=[8,16,24,32,40,64,80]
d=[]
for i in a:
if (i in b )and (i in c):
d.append(i)
print(*d,sep="\n")
https://code.sololearn.com/cLnN0JEat5es/?ref=app
0
Jayakrishna🇮🇳 Thank you ....