Question: I have a (probably quite simple) problem I cannot figure out in Python.

Say I have a list 
`X1 = [1,2,3]` 
with the corresponding list 
`Y1 = [5,6,7]` 
and a list 
`X2 = [2,1,3]` 
with corresponding list 
`Y2 = [8,9,10]`
where `X1` and `X2` contain the same values but in different order. How can I match the order of `X2` to that of `X1`, while the `X2` `Y2` pairs remain intact? The answer should be then `Y2 = [9,8,10]`. 

Thank you in advance!

Answer: 
For a type safe solution, you’d need to define a class holding the desired results. This type may also provide the necessary methods for adding another `Customer` or partial result:

```
public class CustomerProperties {
    private List<Integer> id = new ArrayList<>();
    private List<String> country = new ArrayList<>();
    private List<Integer> customerId = new ArrayList<>();
    private List<String> name = new ArrayList<>();
    private List<String> surname = new ArrayList<>();
    private List<Date> dateOfBirth = new ArrayList<>();

    public void add(Customer c) {
        id.add(c.getId());
        country.add(c.getCountry());
        customerId.add(c.getCustomerId());
        name.add(c.getName());
        surname.add(c.getSurname());
        dateOfBirth.add(c.getDateOfBirth());
    }
    public void add(CustomerProperties c) {
        id.addAll(c.id);
        country.addAll(c.country);
        customerId.addAll(c.customerId);
        name.addAll(c.name);
        surname.addAll(c.surname);
        dateOfBirth.addAll(c.dateOfBirth);
    }
}

```

Then, you can collect all results like

```
CustomerProperties all = customers.stream()
    .collect(CustomerProperties::new, CustomerProperties::add, CustomerProperties::add);

```
You can create a method like so:

```
public <T> List<T> getByFieldName(List<Customer> customerList, Function<Customer, T> field){
    return customerList.stream()
            .map(field)
            .collect(Collectors.toList());
}

```

Then just call your method with the field you want:

```
List<Integer> ids = getByFieldName(customerList, Customer::getId);
List<String> countries = getByFieldName(customerList, Customer::getCountry);
List<Integer> customerIds = getByFieldName(customerList, Customer::getCustomerId);
//...

```