Below you can see the function for extracting separate words from the text. Below you can see the text and code.
import re
text = '''
def function_cal(revenues_shops, surplus_margin, meadian_profit):
median_profit= revenues_shops* surplus_margin
return median_profit
def function_cal_new (revenues_stories_new, surplus_margin_new, meadian_profit):
median_profit= revenues_stories_new* surplus_margin_new
return median_profit
def function_cal_new1 (revenues_stories_new1, surplus_margin_new1, meadian_profit):
median_profit= revenues_stories_new1* surplus_margin_new1
return median_profit
'''
def extraction_variables(text):
splited_table1, splited_table2 = dict(), dict()
lines = text.split('\n')
for line in lines:
x = re.search(r"^def.*:$", line)
if x is not None:
values = x[0].split('def ')[1].split('(')
splited_table1 = values[0]
splited_table2 = values[1][:-2].split(', ')
yield splited_table1, splited_table2
splited_table1, splited_table2 = zip(*extraction_variables(text))
Now I want to put extracted words from splited_table1 and splited_table2 in the same place.
I tried with next line of code:
splited_table1+splited_table2
But after execution of the above line I have results this results:
('function_cal',
'function_cal_new ',
'function_cal_new1 ',
['revenues_shops', 'surplus_margin', 'meadian_profit'],
['revenues_stories_new', 'surplus_margin_new', 'meadian_profit'],
['revenues_stories_new1', 'surplus_margin_new1', 'meadian_profit'])
But instead of having only words separated by commas, I can see a lot of brackets. So can anybody help me how to solve this and to have only words without brackets and quotation marks?