[英]Convert each element in a list to a corresponding (predefined) dictionary value
The coding challenge from Codewars Codewars 的编码挑战
I want to map each corresponding value in an array to my new defined dictionary such that我想将数组中的每个对应值 map 到我新定义的字典中,这样
'NORTH': 1, 'SOUTH': -1, 'EAST': 1, 'WEST': -1
Here, each key corresponds to a an individual element in a given list
and the values in the dict
is what I want the new elements of said list
to equal to.在这里,每个键对应于给定
list
中的一个单独元素,并且dict
中的值是我希望所述list
的新元素等于的值。
I then intend on taking the sum of the new list
to find the "reduced direction"然后我打算对新
list
的总和找到“减少的方向”
Any help would be appreciated.任何帮助,将不胜感激。 Thank you!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.