Counting numbers using for or while

Asked 2 years ago, Updated 2 years ago, 13 views

Number from 0 to 9

after receiving a number

You need to count. (Without count function)

Input value

111222333444567 

Output

0 1 2 3 4 5 6 7

0 3 3 3 3 1 1 1

This is how it should be expressed.

python

2022-09-20 19:24

1 Answers

input = '111222333444567' #Input value
import itertools as it
dict(zip(map(str, range(10)), [0] * 10), **{k: len(list(g)) for k, g in it.groupby(sorted(inputed))})

{'0': 0,
 '1': 3,
 '2': 3,
 '3': 3,
 '4': 3,
 '5': 1,
 '6': 1,
 '7': 1,
 '8': 0,
 '9': 0} #3 is 3. Four is three. Five is one


2022-09-20 19:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.