1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
"""
Created on Wed Oct 12 11:30:17 2022
@author: Erly.Alvarez
You are given list of strings in the format aa9999 i.e. first 2 characters can be anything 'a-z' followed by 4 digits '0-9'.
Write a script to replace the first two characters with sequence starting with '00', '01', '02' etc.
Example 1
Input: @list = ( 'ab1234', 'cd5678', 'ef1342')
Output: ('001234', '015678', '021342')
Example 2
Input: @list = ( 'pq1122', 'rs3334')
Output: ('001122', '013334')
"""
import argparse
p = argparse.ArgumentParser(description='Perl Weekly Challenge 184')
p.add_argument(
"-l", "--list",
nargs="+",
type=str,
default=["ab1234", "cd5678", "ef1342"])
args = p.parse_args()
def char_replacer(argv):
result = []
for idx, val in enumerate(argv):
bypass = f"{idx % 100:02d}"
result.append(bypass + val[2:])
return result
print(char_replacer(args.list))
|