Basically, I have a bunch of numpy arrays each with a list of websites in a larger array. I wanted to, with input from the user, basically return the arrays where the input of the user is the first element of the array. It would return that, the user would input another website, and it would be the second element of the arrays that matched the first time. So for example:
bigarray = [['website1','website2', 'website3', 'website4'],
['website1', 'website7', 'website9', 'website3'],
['website1','website2','website5', 'website9','website24','website36']]
basically if someone were to input 'website1' it would return
{'website2':2, 'website7':1}
after if they were to input website 2 it would output
{'website3':1,"website5":1}
and so on. I hope I was clear, if not, please comment and I'll make it more clear. I don't know how to make this efficient and quick, I've been brainstorming but I can only come up with inefficient methods. Please help,
This is what I have so far, but it doesn't do a dictionary with frequencies. I can't figure out how to get frequencies in the dictionary, nor can I figure out how to get the second third fourth etc. elements searching. This only works for the first element.
import numpy as np
import cherrypy as cp
def initialize(self):
pagearray = np.load("pagearray.npy")
def submit(self, input):
for i in pagearray:
if input==i[0]:
subpagearray += [i[1:]]
possibilities +=i[0]
return possibilities
Thanks, F