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

2024-05-13 22:30:01 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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'},等等

我真的很迷茫。。。有什么想法吗

提前谢谢


Tags: 名称区域列表字典medsup元组大脑
1条回答
网友
1楼 · 发布于 2024-05-13 22:30:01

这样行吗?我不确定您想要什么样的变量。我使用的两个变量是可以用数据填充的简短示例

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

相关问题 更多 >