Advertisement
kingbode

Untitled

Jul 24th, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. '''
  2.  
  3. CODE CHALLENGE - FIND KILLER & NEXT VICTIM
  4. Eric and Terry have been killed by someone they met last week Who is the killer? AND Who is the next Victim?
  5. Below are the people each person met last week
  6. print the answers
  7. input : 'Eric' met ['Jane','John','Mike','Leigh','Todd','Lee','Judy']
  8. 'Jen' met ['Mark','Mike','Leigh','Jim','Lara','John','Bill']
  9. 'Terry' met ['Joe','Sara','Reg','Jill','John','Greg','Bryan']
  10. 'Lara' met ['Pete','Li','Todd','Reg','Jane','Mike','Jen','Ang']
  11.  
  12. output: 'The killer is ???? and the next victim is ???'
  13.  
  14. Try to find a generalised solution that would work for ’any ’ sample and number of people.
  15.  
  16. Have fun!🥳
  17.  
  18. Please share code in editable & Runnable format for others to play with.
  19. And discuss / assist each other with code
  20. Extra points for not using imports...
  21. '''
  22.  
  23.  
  24. input ={'Eric' : ['Jane','John','Mike','Leigh','Todd','Lee','Judy'],
  25.         'Jen' : ['Mark','Mike','Leigh','Jim','Lara','John','Bill'],
  26.         'Terry' : ['Joe','Sara','Reg','Jill','John','Greg','Bryan'],
  27.         'Lara' : ['Pete','Li','Todd','Reg','Jane','Mike','Jen','Ang']
  28. }
  29.  
  30. # github copilot !!!!
  31. # the killer is someone who is common in both lists of Eric and Terry
  32. killer = ''.join(list(set(input['Eric']).intersection(set(input['Terry']))))
  33. print(f'the killer is {killer}')
  34.  
  35. # next victim is someone who will be meeting the killer !!
  36.  
  37. for key,value in input.items():
  38.     if key == 'Eric' or key == 'Terry':
  39.         continue   # <======= they already met the killer , and died !!
  40.     else:
  41.         if killer in value:
  42.             print(f'The next victim is {key}')
  43.             break
  44.         else:
  45.             continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement