Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- PYTHON CODING CHALLENGE - RIGHT PERSON FOR JOB
- * Connect right person with their favorite kind of data/table
- * Eric Likes numbers. John likes strings and Terry likes mixes
- * print as shown, with oe list of the data per person
- input = [[23,31,56],['France','United States'],['Paris',16,'New York',5], ['Bangladesh','Brazil'],[24,42],['Dhaka',17, 'Rio', 'Ipanema']
- ( If you want to change input to other places, feel freeš)
- output:
- "Eric has [23,31,56,24,42]"
- "John has ['France','United States','Bangladesh','Brazil']"
- "Terry has ['Paris',16,'New York',5,'Dhaka',17, 'Rio', 'Ipanema']"
- Have fun!š„³
- Please share code in editable & āRun-ableā format for others to play with.
- Discuss / assist each other with code
- Extra points for not using imports...
- '''
- input = [[23,31,56],['France','United States'],['Paris',16,'New York',5], ['Bangladesh','Brazil'],[24,42],['Dhaka',17, 'Rio', 'Ipanema']]
- favourites = {'Eric': 'numbers',
- 'John': 'strings',
- 'Terry': 'mixes' }
- def checkListNature(_list):
- if all(isinstance(item, int) for item in _list):
- return 'numbers'
- elif all(isinstance(item, str) for item in _list):
- return 'strings'
- else:
- return 'mixes'
- output = {}
- for _list in input:
- if checkListNature(_list) == favourites['Eric']:
- if output.get('Eric') == None:
- output['Eric'] = _list
- else:
- output['Eric'] += _list
- elif checkListNature(_list) == favourites['John']:
- if output.get('John') == None:
- output['John'] = _list
- else:
- output['John'] += _list
- else:
- if output.get('Terry') == None:
- output['Terry'] = _list
- else:
- output['Terry'] += _list
- print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement