I was trying to make a python program that will help me code faster for mysql thru python and I put the shortforms in a dictionary so it can be referenced and replace the values, but I came across a problem that is weird. Isn't the loop supposed to iterate thru the dictionary to find the value but this seems to find the first possible value in the dictionary?
dict1 = {
"selall" : "select * ",
"from" : "from ",
"where" : "where ",
"seldist" : "SELECT DISTINCT ",
"selcount" : "select count ",
"ordby" : "order by ",
"sel" : "select "
}
user = input(">>>> ").split(' ')
command_list = []
a = [i for i in user if i not in dict1]
print(a)
for k,v in dict1.items():
for i in user:
if i==k :
command_list.append(v)
command = ''.join(command_list)
print(command)
print(command_list)
# I have to figure out a way to put the values between the commands
This is the output this the 'sel' key is at the bottom:
>>>> sel this,that from here ordby That
['this,that', 'here', 'That']
from order by select
['from ', 'order by ', 'select ']
But if I put the key above then i.e:- putting the sel
key above from
>>>> sel this,that from here ordby That
['this,that', 'here', 'That']
select from order by
['select ', 'from ', 'order by ']
could anyone explain what's happening?