python - 竞争性编程:如何检查变量的值是否存在于 python 列表中?
问题描述
在我的一项能力倾向测试中提出了以下问题。我尝试使用 python 解决。问题如下:
COVID19 Patients are with identity numbers from 1 to 10.
But few patients are escaped from quarantine.
Find out those patients and write their names and details.
Below are details of patients.
1 Raju
2 Ravi
3 Lakshmi
4 Yash
5 Renu
6 Tanvi
7 Usha
8 Vicky
9 Rocky
10 Manu
输出和输入的格式如下:
Input Format
Line 1: String
Line 2: String
Line 3: String
Line 4: String
Line 5: String
Line 6: String
Line 7: String
Line 8: String
Line 9: String
Constraints
None
Output Format
Line 1: String
示例输入和输出如下所示:
Sample Input 0
Raju
Ravi
Lakshmi
Yash
Tanvi
Usha
Vicky
Rocky
Manu
Sample Output 0
Renu
因此,我将所有名称都赋予了一个名为 Patient[] 的数组。我的问题程序如下:
patient=[
"Raju",
"Ravi",
"Lakshmi",
"Yash",
"Renu",
"Tanvi",
"Usha",
"Vicky",
"Rocky",
"Manu"
]
for i in range(0,):
item=input()
if item not in patient:
print(item)
解决方案
您不能迭代 arange(0,)
因为没有定义端点,它必须是range(0,len(patient))
那么这就是你的循环的样子:
for i in range(0,len(patient)):
item=input()
if item not in patient:
print(item)
推荐阅读
- php - Laravel 在重定向之前保存 cookie
- python - 如何创建字典类型列?
- android - 带有“cordova-plugin-local-notifications”插件的本地通知
- security - 基于 NTAG213 与 Ultralight C 的支付应用程序(使用 Android NFC)
- c# - 有没有办法获得指向泛型类型“in”参数的指针?
- javascript - 为什么 JS Map 函数返回未定义?
- swift - 如何在 Swift 中解开任意深度嵌套的选项?
- design-patterns - 带有单例的工厂模式
- asp.net-mvc - 如何在 MVC 中使用 Razor View 获取去年(如“00/2017”)?
- c - 用逗号将宏参数传递给函数