Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- CODE CHALLENGE - FIND KILLER & NEXT VICTIM
- Eric and Terry have been killed by someone they met last week Who is the killer? AND Who is the next Victim?
- Below are the people each person met last week
- print the answers
- input : 'Eric' met ['Jane','John','Mike','Leigh','Todd','Lee','Judy']
- 'Jen' met ['Mark','Mike','Leigh','Jim','Lara','John','Bill']
- 'Terry' met ['Joe','Sara','Reg','Jill','John','Greg','Bryan']
- 'Lara' met ['Pete','Li','Todd','Reg','Jane','Mike','Jen','Ang']
- output: 'The killer is ???? and the next victim is ???'
- Try to find a generalised solution that would work for ’any ’ sample and number of people.
- Have fun!🥳
- Please share code in editable & Runnable format for others to play with.
- And discuss / assist each other with code
- Extra points for not using imports...
- '''
- input ={'Eric' : ['Jane','John','Mike','Leigh','Todd','Lee','Judy'],
- 'Jen' : ['Mark','Mike','Leigh','Jim','Lara','John','Bill'],
- 'Terry' : ['Joe','Sara','Reg','Jill','John','Greg','Bryan'],
- 'Lara' : ['Pete','Li','Todd','Reg','Jane','Mike','Jen','Ang']
- }
- # github copilot !!!!
- # the killer is someone who is common in both lists of Eric and Terry
- killer = ''.join(list(set(input['Eric']).intersection(set(input['Terry']))))
- print(f'the killer is {killer}')
- # next victim is someone who will be meeting the killer !!
- for key,value in input.items():
- if key == 'Eric' or key == 'Terry':
- continue # <======= they already met the killer , and died !!
- else:
- if killer in value:
- print(f'The next victim is {key}')
- break
- else:
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement