python - 如何在Python中的列表中存储多个字符串?

标签 python list dictionary tuples

我有这个ListOfCoordinates包含 5 个元组的列表(下图),每个索引对应于大脑两个区域的坐标。

enter image description here

我还有一个名为 brain_areas_ROIs 的变量,这是一本字典(下图),其中包含所有可能的大脑区域的名称。

enter image description here

所以我想将获得的所有坐标对的相应大脑区域存储在字典中,例如 dict = {0: 'Frontal_Med_Orb_L', 'Frontal_Sup_Medial_L', 1: 'Frontal_Med_Orb_R', 'Frontal_Sup_Medial_L'} ,等等等等。

我真的对此迷失了......有什么想法吗?

提前致谢!

最佳答案

这样的东西有用吗?我不确定你到底想要什么样的变量。我使用的两个变量是简短的示例,您可以用数据填充它们。

def main():
    ListOfCoordinates = [
        (2, 4),
        (1, 5),
        (6, 3),
        (7, 0)
    ]

    brain_areas_ROIs = {
        0: "Precentral_L",
        1: "Precentral_R",
        2: "Frontal_Sup_L",
        3: "Frontal_Sup_R",
        4: "Frontal_Sup_Orb_L",
        5: "Frontal_Sup_Orb_R",
        6: "Frontal_Mid_L",
        7: "Frontal_Mid_L"
    }

    print(brain_thing(ListOfCoordinates, brain_areas_ROIs))


def brain_thing(coordinates: list, brain_pos: dict) -> list:
    brain_list = []

    for coordinate in coordinates:
        brain_list.append((brain_pos[coordinate[0]], brain_pos[coordinate[1]]))

    return brain_list

关于python - 如何在Python中的列表中存储多个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67796543/

相关文章:

python - 将字典的字符串表示形式转换为真正的字典

python - 如何以正确的方式从pycurl中抽象出来

python - Python 中长度为 n 的一系列空列表?

python - 最长的字母子串 - 从哪里开始

c# - 防止从外部类 c# 访问列表元素

if 语句的 Python 问题

ios - 如何使用 swift 4 在 GMSMapView 上添加按钮

python - 我应该担心在多线程 python 脚本中并发访问字典吗?

python - 编写 python for 循环的更短方法

python - 使用 Django 将数千条记录插入 SQLite 表的有效方法是什么?