Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36fd2d1

Browse files
committed
ch04: use list comprehension
1 parent abdbe66 commit 36fd2d1

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

04_jump_the_five/jump.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_args():
1717
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
1818
)
1919

20-
parser.add_argument("positional", metavar="str", help="Input text")
20+
parser.add_argument("text", metavar="str", help="Input text")
2121

2222
return parser.parse_args()
2323

@@ -27,7 +27,6 @@ def main():
2727
"""Make a jazz noise here"""
2828

2929
args = get_args()
30-
pos_arg = args.positional
3130

3231
jumper = {
3332
"1": "9",
@@ -42,11 +41,7 @@ def main():
4241
"0": "5",
4342
}
4443

45-
for char in pos_arg:
46-
if char in jumper:
47-
print(jumper[char], end="")
48-
else:
49-
print(char, end="")
44+
print("".join([jumper.get(char, char) for char in args.text]))
5045

5146

5247
# --------------------------------------------------

0 commit comments

Comments
 (0)