+ 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
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
+ 1
Another solution 😄
https://code.sololearn.com/c0w1uzVEkR2V/?ref=app
0
if number in numbers:
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
0
Mirielle, can you show me the shorter solution? I would like to see it :)
0
sunshine the shorter version uses count() function
https://code.sololearn.com/c9z0WqC9sT6D/?ref=app
0
Stefanoo thank you for the solution :)