Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def parents(d, name):
- return d[name]
- def grandparents(d, name):
- grandpar = []
- for par in parents(d, name):
- if par in d.keys():
- grandpar += parents(d, par)
- return grandpar
- def find_name(dictionary, value):
- """
- Function to get keys from the dictionary by value
- Input:
- dictionary - dict
- value - any type of value in this dict
- Output:
- names - finded keys
- """
- names = []
- for name, val in dictionary.items():
- if val == value:
- names.append(name)
- return names
- def sibling(d, name):
- par = parents(d, name)
- sibl = find_name(d, par)
- sibl.remove(name)
- return sibl
- def children(d, name):
- chil = []
- for key, val in d.items():
- if name in val:
- chil.append(key)
- return chil
- def grandchildren(d, name):
- grandchil = []
- chil = children(d, name)
- for key, val in d.items():
- for c in chil:
- if c in val:
- grandchil.append(key)
- return(grandchil)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement