DreamSeller92

test

Sep 26th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. def namelist(names):
  2. a = '' #пустая переменная
  3. dict_names = [d['name'] for d in names] #генерируем список имен
  4. for i in dict_names:
  5. if len(dict_names) >= 3: # если больше 3
  6. a = ', '.join(dict_names[:-2]) + ', '+str(dict_names[-2]) + ' & ' + str(dict_names[-1])
  7. return a
  8. elif len(dict_names) == 2: # есди 2
  9. a = str(dict_names[0]) + ' & ' + str(dict_names[1])
  10. return a
  11. elif len(dict_names) == 1: # если 1
  12. a = str(dict_names[0])
  13. return a
  14. else:# все что не влезло
  15. return a
Advertisement
Add Comment
Please, Sign In to add comment