Q:

Write a NumPy program to sort pairs of first name and last name return their indices. (first by last name, then by first name)

0

Write a NumPy program to sort pairs of first name and last name return their indices. (first by last name, then by first name).
first_names = (‘Betsey’, ‘Shelley’, ‘Lanell’, ‘Genesis’, ‘Margery’)
last_names = (‘Battle’, ‘Brien’, ‘Plotner’, ‘Stahl’, ‘Woolum’)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
first_names =    ('Margery', 'Betsey', 'Shelley', 'Lanell', 'Genesis')
last_names = ('Woolum', 'Battle', 'Plotner', 'Brien', 'Stahl')
x = np.lexsort((first_names, last_names))
print(x)

Sample Output:

[1 3 2 4 0]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now