A traveling salesman has to visit clients. He got each client's address e.g. `"432 Main Long Road St. Louisville OH 43071"` as a list.

The basic zipcode format usually consists of two capital letters followed by a white space and five digits.
The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. :

`"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"`.

To ease his travel he wants to group the list by zipcode.
# Task
The function `travel` will take two parameters `r` (addresses' list of all clients' as a string) and `zipcode` and returns a string in the following format:

`zipcode:street and town,street and town,.../house number,house number,...` 

The street numbers must be in the same order as the streets where they belong.

If a given zipcode doesn't exist in the list of clients' addresses return `"zipcode:/"`

# Examples
```
r = "123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432"

travel(r, "OH 43071") --> "OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432"

travel(r, "NY 56432") --> "NY 56432:High Street Pollocksville/786"

travel(r, "NY 5643") --> "NY 5643:/"
```

# Note for Elixir:
In Elixir the empty addresses' input is an empty *list*, not an empty string.

# Note: 
You can see a few addresses and zipcodes in the test cases.

Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code:
def travel(r, zipcode):
	

Solutions:
def travel(r, zipcode):
	streets = []
	nums = []
	addresses = r.split(',')
	for address in addresses:
		if ' '.join(address.split()[-2:]) == zipcode:
			streets.append(' '.join(address.split()[1:-2]))
			nums += address.split()[:1]
	return '{}:{}/{}'.format(zipcode, ','.join(streets), ','.join(nums))


import re

def travel(r, zipcode):
	res = [(m.group(2), m.group(1)) for m in re.finditer('(\\d+) ([^,]+) ([A-Z][A-Z] \\d{5})', r) if zipcode == m.group(3)]
	return '{}:{}/{}'.format(zipcode, ','.join((a[0] for a in res)), ','.join((a[1] for a in res)))


from collections import defaultdict
from re import compile, match
REGEX = compile('(?P<num>\\d+) (?P<adr>.+) (?P<st_zip>[A-Z]{2} \\d{5})')

def travel(addresses, zipcode):
	by_zipcode = defaultdict(lambda : defaultdict(list))
	for address in addresses.split(','):
		m = match(REGEX, address).groupdict()
		by_zipcode[m['st_zip']]['adr'].append(m['adr'])
		by_zipcode[m['st_zip']]['num'].append(m['num'])
	result = by_zipcode[zipcode]
	return '{}:{}/{}'.format(zipcode, ','.join(result['adr']), ','.join(result['num']))


import re

def travel(r, zipcode):
	addresses = [address for address in r.split(',') if re.match('\\d+ .+ {}$'.format(zipcode), address)]
	streets = []
	houses = []
	for address in addresses:
		(house, street) = re.findall('(\\d+) (.+) .* .*', address)[0]
		streets.append(street)
		houses.append(house)
	return zipcode + ':' + ','.join(streets) + '/' + ','.join(houses)


def travel(r, zipcode):
	out = [[], []]
	endstr = zipcode + ':'
	r = r.split(',')
	for data in r:
		if data[len(data) - 8:] == zipcode:
			strt = data.split(' ', 1)[1][:-9]
			apt = data.split(' ', 1)[0]
			out[0].append(strt)
			out[1].append(apt)
	endstr += ','.join(out[0]) + '/'
	endstr += ','.join(out[1])
	return endstr


def travel(r, zipcode):
	return zipcode + ':' + ','.join([' '.join(x.split()[1:]) for x in [x[:-9] for x in r.split(',') if x[-8:] == zipcode]]) + '/' + ','.join([x.split()[0] for x in [x[:-9] for x in r.split(',') if x[-8:] == zipcode]])


def travel(r, zipcode):
	matches = [' '.join(i.split()[:-2]) for i in r.split(',') if ' '.join(i.split()[-2:]) == zipcode]
	return '%s:' % zipcode + ','.join([' '.join(i.split()[1:]) for i in matches]) + '/' + ','.join([''.join(i.split()[:1]) for i in matches])


import re

def travel(r, zipcode):
	r = r.split(',')
	filtered = [*filter(lambda x: re.search(f'{zipcode}$', x), r)]
	(nums, streets) = ([], [])
	for address in filtered:
		(num, street) = address.split(' ', 1)
		nums.append(num)
		streets.append(street.rstrip(' ' + zipcode))
	return filtered != [] and zipcode and f"{zipcode}:{','.join(streets)}/{','.join(nums)}" or f'{zipcode}:/'


def travel(r: str, zipcode: str) -> str:
	(addresses, numbers) = ([], [])
	if zipcode:
		for a in r.split(','):
			(s, _, rem) = a.rpartition(zipcode)
			if s and (not rem):
				(n, a) = s[:-1].split(maxsplit=1)
				numbers.append(n)
				addresses.append(a)
	return f"{zipcode}:{','.join(addresses)}/{','.join(numbers)}"


import re

def travel(r, zipcode):
	addresses = [*[x for x in r.split(',') if re.findall('[A-Z]{2} \\d{5}', x)[0] == zipcode]]
	if not addresses:
		return f'{zipcode}:/'
	numbers = []
	for (i, a) in enumerate(addresses):
		n = re.findall('\\d{1,5}(?= \\w+)', a)[0]
		numbers.append(n)
		addresses[i] = a.strip(n).strip(zipcode)
	return f"{zipcode}:{','.join(addresses)}/{','.join(numbers)}"