+ 3

Help me solve this (using loop)

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
11 Answers
+ 5
sunshine , here is a very basic approach without dictionary or set: https://code.sololearn.com/c8gni3ZN2JIN/?ref=app
3rd Feb 2023, 6:21 PM
Lothar
Lothar - avatar
+ 2
if number in numbers:
2nd Feb 2023, 8:32 PM
Solo
Solo - avatar
+ 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
+ 1
Lothar, ok and thank you for the help :)
3rd Feb 2023, 6:57 PM
sunshine
sunshine - 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
0
Can you teach me how to do For loop .... Addition, multiplication etc
4th Feb 2023, 2:23 PM
Malaika Milli
Malaika Milli - avatar
0
I am the beginners Soo 🙋
4th Feb 2023, 2:24 PM
Malaika Milli
Malaika Milli - avatar