Delete all the keys except one, but keep all the values in python dictonary

I need to create a dictionary where I am able to split all the select attributes, from table, where condition into different list, but it should have just 1 key. So far I have tried the below-

import pandas
import re
import sqlparse

query = "(select, t1.feed_id, t2.eff_dt, name, type from table1 t1 INNER JOIN table2 t2 ON ( t1.eff_dt = t2.eff_dt WHERE t2.eff_dt = CAST ( ('2020/12/20') AS DATE) and ( = 'abc' or'pqr'))"
query2= "SELECT DISTINCT id, feed_id, eff_date FROM"
newInput= input('enter the eff_dt:')
new_where = '("'+newInput+'")'
query1= re.sub("(?<=WHERE t2.eff_dt = CAST \( )(.*)(?= AS DATE)", new_where , query, flags=re.IGNORECASE)
formatted_query = sqlparse.format(query1, reindent=True, keyword_case='lower')
formatted_query1 = sqlparse.format(query2, reindent=True, keyword_case='lower')

a = formatted_query.strip()
a1 = formatted_query1.strip()
newformat = a1+a
dict_list = newformat.split('\n')

dictOfWords = { i : dict_list[i] for i in range(0, len(dict_list) ) }

newDict = dict(zip(dictOfWords.keys(), [v.strip() if isinstance(v,str) else v for v in dictOfWords.values()]))

This takes the input from user for date and gives the output as below-

enter the eff_dt:2022/01/20
{0: 'select distinct id,',
 1: 'feed_id,',
 2: 'eff_date',
 3: 'from(',
 4: 'select,',
 5: 't1.feed_id,',
 6: 't2.eff_dt,',
 7: 'name,',
 8: 'type',
 9: 'from table1 t1',
 10: 'inner join table2 t2 on (t1.eff_dt = t2.eff_dt',
 11: 'where t2.eff_dt = cast (("2022/01/20") as DATE)',
 12: "and ( = 'abc'",
 13: "or'pqr'))"}

But I need the output as below-

{0: 'select distinct id,','feed_id,','eff_date','from(','select,','t1.feed_id,','t2.eff_dt,','name,','type','from table1 t1','inner join table2 t2 on (t1.eff_dt = t2.eff_dt','where t2.eff_dt = cast (("2022/01/20") as DATE)',"and ( = 'abc'","or'pqr'))"}

Is there a way to do it? Remove all the keys except 1, but keep all the values in the dictionary. I would really appreciate some help.

Read more here:

Content Attribution

This content was originally published by Pornima Bansode at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: