+ 1
problem in python in list
How to stop the repetion in frequency distribution?? PLEASE help https://code.sololearn.com/cq4UU8v5GHcc/#py
6 Antworten
+ 5
If you are wondering what is set:
It is a set object, which is very similar to a lists, but:
sets can not be indexed or sliced.
sets can not have duplicate values.
We converted the list a to a set using set() function(*1), which automatically removed the duplicate values.
(1*)not just a function, much more.
+ 5
a little late, but here is my try:
a=[10,20,30,40,30,40,20,45,78,54,10]
print("the list is - ", a)
for i in sorted(list(set(a))):
print(f'Num: {i} is {a.count(i)}')
'''
the list is - [10, 20, 30, 40, 30, 40, 20, 45, 78, 54, 10]
Num: 10 is 2
Num: 20 is 2
Num: 30 is 2
Num: 40 is 2
Num: 45 is 1
Num: 54 is 1
Num: 78 is 1
'''
+ 3
The easiest method is:
for i in set(a):
print(i, "-", a.count(i))
+ 2
Do you mean of using break statements when using nested loops?
+ 2
Oohhh there is a count method ....i totally forggot
+ 2
Thanks, fixed