Given: an array containing hashes of names

Return: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand.

Example:

``` ruby
list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ])
# returns 'Bart, Lisa & Maggie'

list([ {name: 'Bart'}, {name: 'Lisa'} ])
# returns 'Bart & Lisa'

list([ {name: 'Bart'} ])
# returns 'Bart'

list([])
# returns ''
```
``` elixir
list([ %{name: "Bart"}, %{name: "Lisa"}, %{name: "Maggie"} ])
# returns 'Bart, Lisa & Maggie'

list([ %{name: "Bart"}, %{name: "Lisa"} ])
# returns 'Bart & Lisa'

list([ %{name: "Bart"} ])
# returns 'Bart'

list([])
# returns ''
```
``` javascript
list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ])
// returns 'Bart, Lisa & Maggie'

list([ {name: 'Bart'}, {name: 'Lisa'} ])
// returns 'Bart & Lisa'

list([ {name: 'Bart'} ])
// returns 'Bart'

list([])
// returns ''
```
```python
namelist([ {'name': 'Bart'}, {'name': 'Lisa'}, {'name': 'Maggie'} ])
# returns 'Bart, Lisa & Maggie'

namelist([ {'name': 'Bart'}, {'name': 'Lisa'} ])
# returns 'Bart & Lisa'

namelist([ {'name': 'Bart'} ])
# returns 'Bart'

namelist([])
# returns ''
```

Note: all the hashes are pre-validated and will only contain A-Z, a-z, '-' and '.'.

Difficulty: EASY
Starter code: def namelist(names):
	

Solutions:
def namelist(names):
	if len(names) > 1:
		return '{} & {}'.format(', '.join((name['name'] for name in names[:-1])), names[-1]['name'])
	elif names:
		return names[0]['name']
	else:
		return ''


def namelist(names):
	if len(names) == 0:
		return ''
	if len(names) == 1:
		return names[0]['name']
	return ', '.join([n['name'] for n in names[:-1]]) + ' & ' + names[-1]['name']


def namelist(names):
	return ', '.join([name['name'] for name in names])[::-1].replace(',', '& ', 1)[::-1]


def namelist(names):
	names = [hash['name'] for hash in names]
	output = names[:-2]
	output.append(' & '.join(names[-2:]))
	return ', '.join(output)


def namelist(names):
	nameList = [elem['name'] for elem in names]
	return ' & '.join(', '.join(nameList).rsplit(', ', 1))


def namelist(names):
	l = []
	if len(names) == 0:
		return ''
	else:
		for name in names:
			l.append(''.join(list(name.values())))
		str = ', '
		if len(l) == 1:
			return l[0]
		else:
			return str.join(l[:-1]) + ' & ' + l[-1]


namelist = lambda a: ' & '.join(', '.join((d['name'] for d in a)).rsplit(', ', 1))


def namelist(names):
	return ' '.join([names[i]['name'] + (' &' if i == len(names) - 2 else '' if i == len(names) - 1 else ',') for i in range(len(names))])


def namelist(names):
	names_lst = []
	for i in range(len(names)):
		names_lst.append(names[i]['name'])
	names_str = ''
	for i in range(len(names_lst)):
		names_str += names_lst[i]
		if i < len(names_lst) - 2:
			names_str += ', '
		elif i == len(names_lst) - 2:
			names_str += ' & '
	return names_str


def namelist(names):
	return ', '.join((person['name'] for person in (names if len(names) < 2 else names[:-1]))) + (' & ' + names[-1]['name'] if len(names) > 1 else '')