Text file:
Animals
Tiger
Lion
Cat
Mice
Birds
Parrot
Peacock
Hen
chicken
Reptiles
Mammals
I want to dynamically separate the words based on the indentation and store it in a different lists
Expected Output:
a=['Animals','Birds','Reptiles','Mammals']
b=['Tiger','Lion','Parrot','Peacock']
c=['Cat','Hen']
d=['Mice','Chicken']
Here is my code:
a=[]
b=[]
c=[]
d=[]
for i in text:
indent = len(i)-len(i.lstrip())
if indent == 0:
a.append(i)
if indent == 2:
b.append(i)
if indent == 4:
c.append(i)
if indent == 6:
d.append(i)
It gives the expected output but I want it in dynamic approach.