Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 搜索文本文件上的部分stings,打印包括该字符串在内的所有信息(Python)_Python 3.x - Fatal编程技术网

Python 3.x 搜索文本文件上的部分stings,打印包括该字符串在内的所有信息(Python)

Python 3.x 搜索文本文件上的部分stings,打印包括该字符串在内的所有信息(Python),python-3.x,Python 3.x,我想搜索(而不是作为输入)一个人的性别和国家,例如:男性和加拿大。Python将逐行读取,然后打印出所有来自加拿大的男性信息。 在本例中,Python将打印出Alex Baldwin和Gary Allen,但不会打印出其他不符合要求的人(男性和加拿大)。它将打印出所有人的姓名、姓氏、职业、出生日期、性别和原籍国的信息。不能使用正则表达式,也不能使用“查找”命令。有人知道怎么做吗?谢谢你的帮助 这是文本文件: Alex `*---stands for first name

我想搜索(而不是作为输入)一个人的性别和国家,例如:男性和加拿大。Python将逐行读取,然后打印出所有来自加拿大的男性信息。 在本例中,Python将打印出Alex Baldwin和Gary Allen,但不会打印出其他不符合要求的人(男性和加拿大)。它将打印出所有人的姓名、姓氏、职业、出生日期、性别和原籍国的信息。不能使用正则表达式,也不能使用“查找”命令。有人知道怎么做吗?谢谢你的帮助

这是文本文件:

Alex              `*---stands for first name*`                 
Baldwin            *`---stands for last name`*  
Journalist         *`--- stands for occupation`*
03071989           *`--- stands for date of birth`*
M                  *`---- stands for gender`*
Canada             *`--- stands for country`*
Maria
Heizl
Doctor
27091977
F
Germany
Stephen
Chou
Actor
11041989
M
China
Gary
Allen
Dentist
16061981
M
Canada   
你需要一个有你所有数据的词汇表

Dict_all_people[i][0]=名字
Dict_all_people[i][1]=姓
Dict_all_people[i][2]=职业
Dict_all_people[i][3]=生日
Dict_all_people[i][4]=性别
Dict_所有人[i][5]=国家

=='M'**只研究M性别
==“加拿大”**仅研究加拿大国家

希望对你有所帮助,如果你有问题就直接问吧
如果这个答案对你有好处,就接受它,关闭帖子


@SarahMiller Thx,我只是没人在这里。。不管怎样,我真的希望这对你有帮助,更难的是用你所有的数据做口述
Dict_all_people={1:['Alex',    'Baldwin', 'Journalist', '03071989', 'M', 'Canada'],
                 2:['Maria',   'Heizl',   'Doctor',     '27091977', 'F', 'Germany'],
                 3:['Stephen', 'Chou',    'Actor',      '11041989', 'M', 'China'],
                 4:['Gary',    'Allen',   'Dentist',    '16061981', 'M', 'Canada']}


for i in Dict_all_people:
    if Dict_all_people[i][4] == 'M' and Dict_all_people[i][5] == 'Canada':
        print(Dict_all_people[i])