PY
py
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
#Takes a user given string and a user given string pattern, and returns parts of the given string that fit the variables in the string pattern in an array.
import sys
def sscanf(string, pattern):
var_list = []
pointer, s_pointer = 0, 0
while pointer < len(pattern):
if pattern[pointer] == "%" and pointer == len(pattern)-1:
if string[s_pointer] != "%":
return []
elif pattern[pointer] == "%" and pattern[pointer+1] == "d":
if string[s_pointer].isdigit():
dig = ""
while s_pointer < len(string) and string[s_pointer].isdigit():
dig += string[s_pointer]
s_pointer += 1
if s_pointer == len(string):
continue
if string[s_pointer] == "." and "." not in dig:
dig += string[s_pointer]
s_pointer += 1
var_list.append(dig)
else:
return []
pointer += 1
elif pattern[pointer] == "%" and pattern[pointer+1] == "s":
s = ""
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run