Skip to content

Commit c81699b

Browse files
committed
new section for python
1 parent 4e04fef commit c81699b

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

content/pyjournal/freq_numbers.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: 'Freq Digits'
3+
date: 2020-07-07
4+
---
5+
6+
Given an integer number, find the most frequent digit in it.
7+
8+
- how to count things efficiently?
9+
10+
- keep calm and code in Python!
11+
12+
Let use the statistics that comes with python stand library
13+
14+
## Statistic Module
15+
16+
This module provides functions for calculating mathematical statistics of numeric (Real-valued) data.
17+
18+
19+
```python
20+
import statistics
21+
from statistics import mode
22+
```
23+
24+
This module statistics offers a Single mode (most common value) of discrete or nominal data.
25+
The values or method to find this is to convert the vaules into a string and then back again once the frequent digit is
26+
found
27+
28+
29+
```python
30+
def freq_digit(num: int) -> int:
31+
numbers = list(str(num))
32+
return int(mode(numbers))
33+
```
34+
35+
## Trying out a value
36+
37+
Next we want to test a value
38+
39+
40+
```python
41+
num_list = 12345
42+
```
43+
44+
## Finally
45+
46+
we can run the function with some additional values and input
47+
48+
49+
```python
50+
freq_digit(num_list)
51+
```
52+
53+
54+
55+
56+
1
57+
58+
59+
60+
61+
```python
62+
freq_digit(12334433)
63+
```
64+
65+
66+
67+
68+
3
69+
70+
71+
72+
73+
```python
74+
freq_digit(773283277)
75+
```
76+
77+
78+
79+
80+
7
81+
82+
83+
84+
85+
```python
86+
freq_digit(1121)
87+
```
88+
89+
90+
91+
92+
1
93+
94+

0 commit comments

Comments
 (0)