Say i have a dict, dict is a dictonary with dictonary as value
dict = {'**Leon**':{'Name':'Leon L','**follow**':['Apple', 'PPy','Jack','Tommy']},'**Jack**':{'name':'Jack Y','**follow**':['Apple','Cruise','Jay']},'**Tommy**':{'name':'Tommy T','**follow**':['Hill']},'**Apple**':{'name':'Apple A','**follow**':['Jack']},**'Cruise'**:{'name':'Cruise L','**follow**':['Jay']}}
**follow**
means users that is followed by this user, for example:
Leon follows Apple, PPy,Jack,Tommy
and i have query file that has tasks in it. We need to accomplish the task and return a list of usernames (the usernames are the keys in dict, eg 'Leon','Jack','Tommy'), the format of that file is:
SEARCH
Leon
follow
follow-by # there might be many more follow, and follow-by
FILTER
name-include Leon
follow Apple # format: keyword follow, a space and a username. same apply to follow-by username
follow-by Leon # there might be more name-include, , follow username, follow by username
the meaning of the query file: The SEARCH and FILTER are keywords. The line after SEARCH is the starting username (we need to put it in the list, lets name the list user_list). The search specification has the 2 steps (in this case):
- create a list that has Leon in it, call this list L1
- follow says to replace each person p in L1 with people who follows p, then we get L2
- follow-by says to replace each person p in L2 with people who are followed by p (people who are followed by p are in the follow list of the user profile). Then we get L3
The filter specification (in this example):
- for each person p in L3, if p's name has 'Leon' in it, the user is kept in the list.Then we get L4
- for each person p in L4, if p follows Apple, then p is kept in the list, we get L5
- for each person p in L5, if p is followed by Leon, p is kept in the list. Then we get our final list. We need to return the final list
Can anyone help me to write a program that can accomplish the task?