# Untitled

a guest
Jul 10th, 2020
29
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import pprint
2.
3. def registerTreat(lis): #lis = a list of parameters
4.     lSize = len(lis)
5.     if lSize == 0 or lSize == 1 or lSize == 2:
6.         print('error')
7.     elif lSize == 3:
8.         try:
9.             t[lis[0]][lis[1]] = lis[-1]
10.         except:
11.             try:
12.                 t[lis[0]] = {}
13.                 t[lis[0]][lis[1]] = lis[-1]
14.             except:
15.                 print('error 1')
16.     elif lSize == 4:
17.         try:
18.             t[lis[0]][lis[1]][lis[2]] = lis[-1]
19.         except:
20.             try:
21.                 t[lis[0]][lis[1]] = {}
22.                 t[lis[0]][lis[1]][lis[2]] = lis[-1]
23.             except:
24.                 try:
25.                     t[lis[0]] = {}
26.                     t[lis[0]][lis[1]] = {}
27.                     t[lis[0]][lis[1]][lis[2]] = lis[-1]
28.                 except:
29.                     print('error 2')
30.     #elif lsize == 5
31.         #etc
32.     #elif lsize == 6
33.         #etc
34.     #elif lsize == 7
35.         #etc
36.     else:
37.         print('function error')
38.     return
39.
40. #example usage:
41. t = {}
42. value = 0.3
43. stage = 'pre'
44. registerTreat(['treatment','subtreatment', stage, value])
45. pprint.pprint(t)
46.
47. # sometimes the output will be:
48. # {'treatment': {'subtreatment': {'pre': 0.3}}}
49.
50. # and sometimes it will be:
51. # {'treatment': {'subtreatment': {'pre': [0.3]}}}
52.
53. # I never call the function like this: registerTreat(['treatment','subtreatment', stage, [value]])
RAW Paste Data