I'm creating this search like query in python that gathers ids and pars them with names like a whois database sort of.
so lets say this is my data in a .txt file
["81448068", "jimmy"]
["69711823", "bob"]
["92739493", "kyle, jimmy"]
["96399981", "kyle"]
["40112089", "john, peter"]
["79784393", "matthew, chad"]
["749968","bob, jimmy"]
The Id's are on the left column and on the right it's the names associated with it. How would I use some type of while or for loop to conduct a search of that data till all names are matched fully? and this method should work if any data is added, I'll show you what I have currently, but on a larger txt file with more names it would not work
def getNames(name):
x = []
f = open("names.txt","r") # that data up there represents names.txt
for line in f.readlines():
rid,names = json.loads(line.strip())
if name in names:
x += names.split(", ")
return list(set(x))
I want to cycle those names back into get names to get more names that are associated with the names that are returned in x, but I would have to manualy add another for alot is there some type of while that would loop this till all matches associated with the names are found? So doing getNames("jimmy") would return,
["bob","jimmy","kyle"]
Then it would check all names associated with bob, all names associated with those till there are no more associated, and it would do that for jimmy and Kyle as well.
So basically, It would search the initial name, in this case lets use jimmy. It returns the names associated with "jimmy" then it would search each individual name associated with that so lets say it returns, ["bob","jimmy","kyle"] It would then take bob, search all the names with that name in the names then search all of those names and search all of those names until it conducted all the names then it would do jimmy do the same and then go to Kyle and do the same. I could do this with a for but, I would need to add multiple fors depending on how extensive I want the search to be, how would I make it a while so it conducts the data till all matches are found.
for line in f.readlines()=>for line in f; also closefat the end or usewith.