gpt4 book ai didi

python - 替换列表中的单词

转载 作者:行者123 更新时间:2023-11-28 18:59:08 24 4
gpt4 key购买 nike

我想以下列格式在屏幕上显示住在马德里的所有用户:

居住在“CITY”的用户“NAME”年龄为“AGE”岁,其债务为:“DEBT”欧元。

正如您所看到的保存马德里的不同方式,我想找到一种方法来打印这些用户,因为一些人用大写字母书写而其他人没有,他们都住在马德里。

students = [
('Marcos', 23, 'Madrid', 850, '2388711341'),
('Elena', 35, 'MaDrid', 360, '0387700342'),
('Carmen', 21, 'Getafe', 50, '0014871388'),
('Carlos', 41, 'MAdrid', 580, '00887118456'),
('Maria', 28, 'Madrixx', 150, '587')
]

对于学生项目: 学生、年龄、城镇、债务、id = item

想要的结果:

The user Marcos lives in Madrid, has an age of 23 years old and its debt is: 850 EUR.

The user Elena lives in Madrid, has an age of 35 years and its debt is: 360 EUR.

The user Carlos lives in Madrid, has an age of 41 years old and its debt is: 580 EUR.

The user Maria lives in Madrid, has an age of 28 years old and its debt is: 150 EUR.

最佳答案

确实很难确定您想要什么,但如果您想打印居住在马德里的校友数据,请尝试以下操作。

students = [
('Marcos', 23, 'Madrid', 850, '2388711341'),
('Elena', 35, 'MaDrid', 360, '0387700342'),
('Carmen', 21, 'Getafe', 50, '0014871388'),
('Carlos', 41, 'MAdrid', 580, '00887118456'),
('Maria', 28, 'Madrixx', 150, '587')
]



for student_detail in students:
if student_detail[2].lower().startswith('madri'):
print(f"The user {student_detail[0]}, lives in Madrid. S/He is {student_detail[1]} years old and has {student_detail[3]} as debt")

关于python - 替换列表中的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54732741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com