+ 3
Help me solve this (using loop)
What I want to do is to output the amount that each number has, using loop
11 Answers
+ 5
sunshine ,
here is a very basic approach without dictionary or set:
https://code.sololearn.com/c8gni3ZN2JIN/?ref=app
+ 2
if number in numbers:
+ 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
+ 1
Lothar, ok and thank you for the help :)
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 :)
0
Can you teach me how to do For loop .... Addition, multiplication etc
0
I am the beginners Soo 🙋