+ 1

Help me solve this (using loop)

So this is my code https://code.sololearn.com/c3RQbFQX43Ys/?ref=app What I want to do is to output the amount that each number has, using loop

2nd Feb 2023, 8:09 PM
sunshine
sunshine - avatar
7 Answers
+ 1
It's kind of blank, but I tried to search on the internet and haven't found anything that could help me
2nd Feb 2023, 8:10 PM
sunshine
sunshine - avatar
2nd Feb 2023, 9:37 PM
Stefanoo
Stefanoo - avatar
0
if number in numbers:
2nd Feb 2023, 8:32 PM
Solo
Solo - avatar
0
I have reviewed your codes and it appears that you are making a condition that will never happen i.e Always False such as comparing if an integer is a list. There are several ways to fix this problem especially using a oneline code, list comprehension etc. I'll assume you want to do it without using count() function so I'll be telling you the procedure. 1. Create a set of the number list S, so you can have a container, containing the unique items in the list 2. Create another list LS that is the same size as the original list, but all values initialised to zero 2. Loop through each items in S, and calculate the number of times they appears in the original list, updating their respected index in LS. This is how I write it.. but if you want a shorter solution, let me know https://code.sololearn.com/c2q1GmLX62zk/?ref=app
2nd Feb 2023, 8:41 PM
Mirielle
Mirielle - avatar
0
Mirielle, can you show me the shorter solution? I would like to see it :)
2nd Feb 2023, 8:54 PM
sunshine
sunshine - avatar
0
sunshine the shorter version uses count() function https://code.sololearn.com/c9z0WqC9sT6D/?ref=app
2nd Feb 2023, 9:08 PM
Mirielle
Mirielle - avatar
0
Stefanoo thank you for the solution :)
2nd Feb 2023, 9:41 PM
sunshine
sunshine - avatar