Advertisement
kingbode

Untitled

Aug 7th, 2022
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. '''
  2. PYTHON CODING CHALLENGE - RIGHT PERSON FOR JOB
  3. * Connect right person with their favorite kind of data/table
  4. * Eric Likes numbers. John likes strings and Terry likes mixes
  5. * print as shown, with oe list of the data per person
  6. input = [[23,31,56],['France','United States'],['Paris',16,'New York',5], ['Bangladesh','Brazil'],[24,42],['Dhaka',17, 'Rio', 'Ipanema']
  7. ( If you want to change input to other places, feel freešŸ‘)
  8. output:
  9. "Eric has [23,31,56,24,42]"
  10. "John has ['France','United States','Bangladesh','Brazil']"
  11. "Terry has ['Paris',16,'New York',5,'Dhaka',17, 'Rio', 'Ipanema']"
  12. Have fun!šŸ„³
  13. Please share code in editable & ā€™Run-ableā€™ format for others to play with.
  14. Discuss / assist each other with code
  15. Extra points for not using imports...
  16. '''
  17.  
  18. input = [[23,31,56],['France','United States'],['Paris',16,'New York',5], ['Bangladesh','Brazil'],[24,42],['Dhaka',17, 'Rio', 'Ipanema']]
  19.  
  20. favourites = {'Eric': 'numbers',
  21.                 'John': 'strings',
  22.              'Terry': 'mixes' }
  23.  
  24. def checkListNature(_list):
  25.     if all(isinstance(item, int) for item in _list):
  26.         return 'numbers'
  27.     elif all(isinstance(item, str) for item in _list):
  28.         return 'strings'
  29.     else:
  30.         return 'mixes'
  31.  
  32. output = {}
  33. for _list in input:
  34.     if checkListNature(_list) == favourites['Eric']:
  35.         if output.get('Eric') == None:
  36.             output['Eric'] = _list
  37.         else:
  38.             output['Eric'] += _list
  39.     elif checkListNature(_list) == favourites['John']:
  40.         if output.get('John') == None:
  41.             output['John'] = _list
  42.         else:
  43.             output['John'] += _list
  44.     else:
  45.         if output.get('Terry') == None:
  46.             output['Terry'] = _list
  47.         else:
  48.             output['Terry'] += _list
  49.  
  50. print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement