1

I have below dictionary values. Example:

dic = {'ID1': ['Name1', 'Name2'],
 'ID2': ['Name1', 'Name3'],
 'ID3': ['Name2']}

I want to print address of every matched names from above dict values into below format.

Example Output:

['ID1', 'adress1' ,'adress2'],
['ID2', 'adress1' ,'adress3'],
['ID3', 'adress2']

Below is my example code of database table that has "Emp_ID", "Emp_Name", "Emp_Address". The dict values are "Emp_Names", that should be match emp_Names and get the Adresses in to the list as Example out.

import sqlite3
conn=sqlite3.connect('emp.db')
conn.execute("""CREATE TABLE IF NOT EXISTS branch
 (Emp_ID TEXT UNIQUE,
 Emp_Name TEXT UNIQUE,
 Emp_Address TEXT
 )""")
conn.execute("""INSERT OR IGNORE INTO branch(Emp_ID, Emp_Name, Emp_Address) \
 VALUES('Emp1', 'Name1', 'adress1')""")
conn.execute("""INSERT OR IGNORE INTO branch(Emp_ID, Emp_Name, Emp_Address) \
 VALUES('Emp2', 'Name2', 'adress2')""")
conn.execute("""INSERT OR IGNORE INTO branch(Emp_ID, Emp_Name, Emp_Address) \
 VALUES('Emp3', 'Name3', 'adress3')""")
conn.execute("""INSERT OR IGNORE INTO branch(Emp_ID, Emp_Name, Emp_Address) \
 VALUES('Emp4', 'Name4', 'adress4')""")
conn.execute("""INSERT OR IGNORE INTO branch(Emp_ID, Emp_Name, Emp_Address) \
 VALUES('Emp5', 'Name5', 'adress5')""")
conn.commit()
conn.close()

For example 'ID1' (column) should not to be changed. And 'name1' should take its address and 'name2'should take its address and all matched names should take their addresses. Which statements are useful for my scenario. Is it possible? If possible how to to?

asked Oct 30, 2020 at 6:05

1 Answer 1

0
answered Oct 31, 2020 at 3:30
2
  • I think your above suggestion is to use get dictionary from SQLite. But I want to get the data from SQLite using my example dictionary values. Commented Oct 31, 2020 at 6:08
  • 1
    And I have edited my Question. Commented Oct 31, 2020 at 6:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.