'Converting a dataset from one for to another

I have one dataset in a list form and I want to convert it into another dataset under certain conditions. Python is the language I am using.

For instance:

Conditions "a" = 1 "b" = 2 "c" = 3

input_list = ["a", "b", "c"]

something happens

output_list = [1, 2, 3]

What to do? Thanks!



Solution 1:[1]

  1. Represent your set of conditions in a dictionary:
conditions = {
    "a": 1,
    "b": 2,
    "c": 3
}
  1. Use that dictionary in order to generate the output:
input_list = ["a", "b", "c"]
output_list = [conditions[x] for x in input_list]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bbbbbbbbb