Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def namelist(names):
- a = '' #пустая переменная
- dict_names = [d['name'] for d in names] #генерируем список имен
- for i in dict_names:
- if len(dict_names) >= 3: # если больше 3
- a = ', '.join(dict_names[:-2]) + ', '+str(dict_names[-2]) + ' & ' + str(dict_names[-1])
- return a
- elif len(dict_names) == 2: # есди 2
- a = str(dict_names[0]) + ' & ' + str(dict_names[1])
- return a
- elif len(dict_names) == 1: # если 1
- a = str(dict_names[0])
- return a
- else:# все что не влезло
- return a
Advertisement
Add Comment
Please, Sign In to add comment