Skip to content

Instantly share code, notes, and snippets.

@kusal1990
Created June 24, 2022 07:58
Show Gist options
  • Save kusal1990/cd9e07f5e7c456d4d4e94a53b52e895a to your computer and use it in GitHub Desktop.
Save kusal1990/cd9e07f5e7c456d4d4e94a53b52e895a to your computer and use it in GitHub Desktop.
def data_generator(a):
'''
This function will accept a data point and returns a list of options
converts the only_options list of options.
Output will be as follows:
options = [option_1, option_2, option_3, option_4, option_5]
Note: If there's no option E then it will be written as 'None of the above'.
'''
options = []
if '(A)' in a:
option_1 = a.split('(B)')[0].replace('(A)','').lstrip()
b = ' '.join(i for i in a.split() if i not in option_1)
option_2 = b.split('(C)')[0].replace('(B)','').replace('(A)','').lstrip()
c = ' '.join(i for i in b.split() if i not in option_2)
option_3 = c.split('(D)')[0].replace('(C)','').replace('(B)','').replace('(A)','').lstrip()
if '(D)' not in c:
option_4 = 'None of the above'
option_5 = 'None of the above'
else:
if '(E)' not in c:
option_4 = c.split('(D)')[1].lstrip()
option_5 = 'None of the above'
else:
d = ' '.join(i for i in c.split() if i not in option_3)
option_4 = d.split('(E)')[0].replace('(D)','').replace('(C)','').replace('(B)','').replace('(A)','').lstrip()
option_5 = d.split('(E)')[1].lstrip()
else:
option_1 = a.split('(2)')[0].replace('(1)','').lstrip()
b = ' '.join(i for i in a.split() if i not in option_1)
option_2 = b.split('(3)')[0].replace('(2)','').replace('(1)','').lstrip()
c = ' '.join(i for i in b.split() if i not in option_2)
option_3 = c.split('(4)')[0].replace('(3)','').replace('(2)','').replace('(1)','').lstrip()
if '(4)' in c:
option_4 = c.split('(4)')[1].lstrip()
else:
option_4 = 'None of the above'
option_5 = 'None of the above'
options = [option_1, option_2, option_3, option_4, option_5]
return options
@kusal1990
Copy link
Author

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment