Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. '''
  2. You have a list of dictionaries with the following general structure:
  3. presidents =
  4. [ {'name':'George Washington', 'vp':'John Adams'},
  5. {'name':'John Adams', 'vp':'Thomas Jefferson'},
  6. {'name':'Zachary Taylor', 'vp':'Millard Fillmore'},
  7. {'name':'Dwight D. Eisenhower', 'vp':'Richard Nixon'},
  8. {'name':'Richard Nixon', 'vp':'Spiro Agnew'},
  9. {'name':'Richard Nixon', 'vp':'Gerald Ford'}, ....]
  10.  
  11. For example, George Washington was a president who had John Adams serve as his Vice President ("vp").
  12. Note that if a president served for more than one term or had multiple vice presidents, there could be multiple dictionaries listed for that president.
  13.  
  14. promoted_vp_ (presidents) will return the list of all vice presidents that also served as president.
  15. E.g. if presidents consists of only the dictionaries listed above:
  16. It returns the list {'John Adams', 'Richard Nixon'}
  17. '''
  18.  
  19.  
  20. #PF-Prac-43
  21.  
  22. def find_promoted_vp(presidents_dict):
  23. #start writing your code here
  24. president=list(set([i["name"] for i in presidents_dict]))
  25. vp=[i["vp"] for i in presidents_dict]
  26. promoted_vp_list=[i for i in president if i in vp]
  27. return promoted_vp_list
  28.  
  29. def find_presidents_vp(presidents_dict,duration):
  30. #start writing your code here
  31. president=list(set([i["name"] for i in presidents_dict]))
  32. dstart,dend=map(int,duration.split("-"))
  33. promoted_vp_list=[]
  34. # print(start,end)
  35. for i in presidents_dict:
  36. p_start,p_end=map(int,i["period"].split("-"))
  37. if p_start>=dstart and p_end<=dend and i["vp"] in president:
  38. promoted_vp_list.append(i["vp"])
  39. return promoted_vp_list
  40.  
  41.  
  42. presidents_dict=[{'name':'George Washington', 'vp':'John Adams','period':'1990-1993'},
  43. {'name':'John Adams', 'vp':'Thomas Jefferson','period':'1994-1996'},
  44. {'name':'Zachary Taylor', 'vp':'Millard Fillmore','period':'1997-1999'},
  45. {'name':'Dwight D. Eisenhower', 'vp':'Richard Nixon','period':'1999-2001'},
  46. {'name':'Richard Nixon', 'vp':'Spiro Agnew','period':'2001-2002'},
  47. {'name':'Richard Nixon', 'vp':'Gerald Ford','period':'2002-2004'}]
  48.  
  49. print("The president and vice president details:",presidents_dict)
  50. output=find_promoted_vp(presidents_dict)
  51. print("The list of vice presidents who also got promoted as presidents:",output)
  52. duration='1999-2005'
  53. print("The president and vice president details:",presidents_dict)
  54. print("Given duration:",duration)
  55. output1=find_presidents_vp(presidents_dict, duration)
  56. print("The list of vice presidents who also got promoted as presidents in the given duration:",output1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement