Python Forum
Thread Rating:
  • 3 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matching question
#6
thanks guys for the quick help, much appreciated!

I have now replaced "participants" with the participant names from a database table:

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()

paid = ('Betinna', 'Amelia')


match = 0
for name in names:
    for namepaid in paid:
        if name == namepaid:
            match += 1

print(match)
Output:
0
If I print the names it looks likes this:
print(names)
Output:
[('Amelia',), ('Alden',), ('Bettina',), ('Billy Ray',), ('Bodean',), ('Bucephelus',), ('Buddy',), ('Casey',), ('Charlton',), ('Cleavon',), ('Cletus',), ('Clyde',), ('Cooter',), ('Daisy',), ('Doc',), ('Duke',), ('Elrod',), ('Georgina',), ('Homer',), ('Huck',), ('John Boy',), ('Percy',), ('Quinn',), ('Robbie',), ('Stella',)] Process finished with exit code 0
I have tried to strip the names first but that didn't change the result.

Any tips on how to the handle the data coming from the db before the match works?
Reply


Messages In This Thread
matching question - by takaa - Nov-21-2017, 10:14 AM
RE: matching question - by heiner55 - Nov-21-2017, 11:11 AM
RE: matching question - by takaa - Nov-21-2017, 11:35 AM
RE: matching question - by snippsat - Nov-21-2017, 01:55 PM
RE: matching question - by heiner55 - Nov-21-2017, 02:29 PM
RE: matching question - by takaa - Nov-21-2017, 03:10 PM
RE: matching question - by heiner55 - Nov-21-2017, 03:19 PM
RE: matching question - by takaa - Nov-21-2017, 04:11 PM
RE: matching question - by iFunKtion - Nov-21-2017, 07:01 PM
RE: matching question - by takaa - Nov-23-2017, 10:14 AM
RE: matching question - by heiner55 - Nov-23-2017, 08:33 AM
RE: matching question - by heiner55 - Nov-23-2017, 11:34 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020