0

i want to intialize number of variables according to number of cases in my switch case as i want it to be dynamic any number of cases to work not only 2

statment=[]
body=[]
switch=[]
cc=[]
case1=[]
case2=[]
cases=[]

for x in range(0,len(cc)):
    if cc[x-1] !="break":
        case1.append(cc[x])  #keda e7na hena 5adna awel statment men el cases of hya dynamic
    else:
        t=x
        break
for x in range(t+1,len(cc)):
    if cc[x-1] !="break":
        case2.append(cc[x]) #keda ana gebt el case el 2
    else:
        d=x # ba3raf ana we2ft feeen 3alshan abda2 el mara ely gaia menha 
        break

print(statment)
print(switch)
print(case1)
print(case2)
omar ezzat
  • 11
  • 1
  • 3
    Based on what your literal question, do you know about/have you considered a `dict()`? Based on your code, can you elaborate what you're actually trying to do? It's not very clear. – Kache Dec 21 '22 at 00:57
  • i am trying to make syntax tree of switch case so i am trying to put each part of code i a list then arrange it in the form of the nltk for drawing it so i am trying to make it generic as any amount of cases should work – omar ezzat Dec 21 '22 at 13:46
  • okay... can you give a concrete end-to-end example? Just going by your statement, the following dictionary satisfies: `switch_and_cases = {'case1': 'case1_value', 'case2': 'case2_value'}`. It maps any number of cases to their corresponding values. – Kache Dec 22 '22 at 00:54

0 Answers0