matching question - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: matching question (/thread-6413.html) Pages:
1
2
|
RE: matching question - takaa - Nov-23-2017 (Nov-21-2017, 07:01 PM)iFunKtion Wrote: A slightly simpler way would be to just use the one for loop, as you only need to iterate through one list and check if each iteration is in the other list: Thanks! The final code including writing back each match to the db is: import psycopg2 as p import re conn = p.connect ("dbname='participants_db' user='postgres' host= 'localhost'") cur = conn.cursor() cur.execute("select participant_name from participants") names = cur.fetchall() cur2 = conn.cursor() cur2.execute("select paid_name from participants_paid") paid = cur2.fetchall() match = 0 for name in names: if name in paid: match += 1 cur.execute("UPDATE participants SET participant_paid = 'Yes' WHERE participant_name = (%s)", (name,)) conn.commit() RE: matching question - heiner55 - Nov-23-2017 Thanks for the update. |