-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask7_3.py
More file actions
53 lines (42 loc) · 1.41 KB
/
Copy pathtask7_3.py
File metadata and controls
53 lines (42 loc) · 1.41 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import sys
def func(line):
myList = []
for i in line:
if i == "[" or i == "]" or i == "(" or i == ")" or i == "{" or i == "}" or i == "<" or i == ">":
myList.append(i)
if len(myList) == 0:
return True
elif myList.count("[") == myList.count("]") and myList.count("(") == myList.count(
")") and myList.count("{") == myList.count("}") and myList.count(
"<") == myList.count(">"):
j = 0
try:
while j != range(len(myList)):
if myList[j] == "(" and myList[j + 1] == ")":
myList.pop(j)
myList.pop(j)
j = 0
elif myList[j] == "{" and myList[j + 1] == "}":
myList.pop(j)
myList.pop(j)
j = 0
elif myList[j] == "[" and myList[j + 1] == "]":
myList.pop(j)
myList.pop(j)
j = 0
elif myList[j] == "<" and myList[j + 1] == ">":
myList.pop(j)
myList.pop(j)
j = 0
else:
j += 1
except:
if (len(myList)) == 0:
return True
else:
return False
else:
return False
line = input("Enter string : ")
print("Result : ", func(line))