Skip to content

Commit 8317d5d

Browse files
Merge pull request geekcomputers#292 from luke-zhou/master
Replace map function with list comprehension
2 parents 82cd561 + 8a0b96d commit 8317d5d

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
*.pyc

4 Digit Number Combinations.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

four_digit_num_combination.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
""" small script to learn how to print out all 4-digit num"""
2+
3+
# ALL the combinations of 4 digit combo
4+
def four_digit_combinations():
5+
""" print out all 4-digit numbers in old way"""
6+
numbers = []
7+
for code in range(10000):
8+
code = str(code).zfill(4)
9+
print(code)
10+
numbers.append(code)
11+
12+
# Same as above but more pythonic
13+
def one_line_combinations():
14+
""" print out all 4-digit numbers """
15+
numbers = [str(i).zfill(4) for i in range(10000)]
16+
print(numbers)

0 commit comments

Comments
 (0)