Here is an example list and the desired output:
list = ['1 Michael Jessica', '2 Christopher Ashley', '3 Matthew Brittany', '4 Joshua Amanda']
output = [ 'Michael 1', 'Jessica 1', 'Christopher 2', 'Ashley 2', 'Matthew 3', 'Brittany 3', etc]
# Then I sort it but that doesn't matter right now
I'm a python newbie and combined the concepts I understand to yield this horrendously ridiculous code that I'm almost embarrassed to post. No doubt there is a proper and easier way! I'd love some advice and help. Please don't worry about my code or editing it. Just posting it for reference if it helps. Ideally, brand new code is what I'm looking for.
list = ['1 Michael Jessica', '2 Christopher Ashley', '3 Matthew Brittany', '4 Joshua Amanda']
list3 = []
list4 = []
y = []
for n in list:
x = n.split()
y.append(x)
print(y)
for str in y:
for pos in range(0, 3, 2): # Number and Name 1
test = str[pos]
list3.append(test)
for str in y:
for pos in range(0, 2): # Number and Name 2
test = str[pos]
list4.append(test)
list3.reverse()
list4.reverse()
print(list3)
print(list4)
length = int(len(list3) / 2)
start = 0
finish = 2
length2 = int(len(list4) / 2)
start2 = 0
finish2 = 2
for num in range(0, length):
list3[start:finish] = [" ".join(list3[start:finish])]
start += 1
finish += 1
for num in range(0, length):
list4[start2:finish2] = [" ".join(list4[start2:finish2])]
start2 += 1
finish2 += 1
print(list3)
print(list4)
list5 = list3 + list4
list5.sort()
print(list5)