I have a list of strings:
ls = ['elev', 'solRd']
I want to create a a new list, with nested list of two elements, where the second element actually better explains the meaning of the first one.
ls.out = [["elev", "elevation"], ["solRd", "solRadiation"]]
I have only few strings, which will repeat, so I would like to specify it manually.
Ie.
if element is 'elev' -> new pair item will be 'elevation';
if element is 'solRd'-> new element 'solarRadiation', etc.
This seems pretty easy but I am relatively new to python and I cannot figure it our.
I have tried to subset my element by name ls['a'] and include it to new list, but even the subsetting by name dis not worked.. I don't want to subset it by index, in case my string order will change.
meanings = {
"elev": "elevation",
"solRd": "solRadiation"
}
ls = ["elev", "solRd"]
lists = [[item, meanings.get(item, "")] for item in ls]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With