-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.py
68 lines (46 loc) · 1.29 KB
/
test2.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
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
54
55
56
57
58
59
60
61
62
63
64
from copy import deepcopy
def grep(oidlist, keyword):
if 'disabled' in keyword:
return oidlist
else:
res = {}
for k, v in oidlist.items():
for i in keyword:
if i in str(v):
res[k] = oidlist[k]
oidlist = res
return oidlist
def grepv(oidlist, keyword):
res = deepcopy(oidlist)
for k, v in res.items():
for i in keyword:
if i in str(v):
del oidlist[k]
return oidlist
dict = {'1321': 'Fa1', '1234': 'Fa2', '3123': 'Gi1', '23': 'Vlan3'}
while True:
filter_choosing = input('grep[1] or grep -v [2] [default: without]: ') or 'without'
if filter_choosing == 'without':
print('No filters applied')
break
elif filter_choosing == '1':
Filter = input('Filter: ') or 'disabled'
inputs = Filter.split(' ')
dict = grep(dict, inputs)
elif filter_choosing == '2':
Filter = input('Filter: ') or 'disabled'
inputs = Filter.split(' ')
grepv(dict, inputs)
else:
print('Wrong choice')
break
print(dict)
'''
while True:
Filter = input('Filter: ') or 'disabled'
values = Filter.split(' ')
grep(dict, values)
print(dict)
if 'disabled' in Filter:
break
'''