1

I am pulling a list of tables from MySQL and it returns data in this format:

[('A_one_day_minute',)
('A_one_month_daily',)
('A_one_year_daily',)
('A_one_year_weekly',)
('A_six_month_daily',)
('A_three_day_minute',)
('A_three_month_daily',)
('A_three_year_weekly',)
('A_two_day_minute',)
('A_two_month_daily',)
('A_two_year_daily',)
('A_two_year_weekly',)]

However to use this data in the next portion of my code which is to go through each table and insert data into it, I need it in the format below.

Notice even the last tuple at the end of the code above has a comma that will need to be removed.

Desired Format:

('A_one_day_minute',
'A_one_month_daily',
'A_one_year_daily',
'A_one_year_weekly',
'A_six_month_daily',
'A_three_day_minute',
'A_three_month_daily',
'A_three_year_weekly',
'A_two_day_minute',
'A_two_month_daily',
'A_two_year_daily',
'A_two_year_weekly')

I'm not sure how to go about doing this and any help is appreciated, thank you!

1
  • try tuple(map(lambda x:x[0],a)), where 'a' is the list of tuples. Commented Jan 27, 2020 at 4:25

1 Answer 1

1

Does this solution good for you?

x = [('A_one_day_minute',),
    ('A_one_month_daily',),
    ('A_one_year_daily',),
    ('A_one_year_weekly',),
    ('A_six_month_daily',),
    ('A_three_day_minute',),
    ('A_three_month_daily',),
    ('A_three_year_weekly',),
    ('A_two_day_minute',),
    ('A_two_month_daily',),
    ('A_two_year_daily',),
    ('A_two_year_weekly',)]

f = []
for i in x:
    for j in i:
        f.append(j)
print(tuple(f))

or

H = tuple(j for j in i for i in x)
print(H)

or

print(tuple(map(lambda v:v[0],x)))

The result:

('A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly', 'A_two_year_weekly')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.