problem in python in list | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

problem in python in list

How to stop the repetion in frequency distribution?? PLEASE help https://code.sololearn.com/cq4UU8v5GHcc/#py

22nd Jun 2019, 6:27 PM
Rahul guha
Rahul guha - avatar
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.
22nd Jun 2019, 8:34 PM
Seb TheS
Seb TheS - avatar
+ 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 '''
22nd Jun 2019, 8:11 PM
Lothar
Lothar - avatar
+ 3
The easiest method is: for i in set(a): print(i, "-", a.count(i))
22nd Jun 2019, 6:55 PM
Seb TheS
Seb TheS - avatar
+ 2
Do you mean of using break statements when using nested loops?
22nd Jun 2019, 6:51 PM
Seb TheS
Seb TheS - avatar
+ 2
Oohhh there is a count method ....i totally forggot
22nd Jun 2019, 6:57 PM
Rahul guha
Rahul guha - avatar
+ 2
Thanks, fixed
22nd Jun 2019, 7:43 PM
Seb TheS
Seb TheS - avatar