python - 在python中如何比较两个列表,我们可以不区分大小写?
问题描述
如果 current_users 中存在“Maurya”,则不应接受“MAURYA”作为可用用户名。
current_users = ["amit", "ajit", "nishant", "mohit", "Maurya"]
new_users = ["deepak", "manish", "maurya", "akhil", "ajit"]
for new_user in new_users:
if new_user in current_users:
print(f"{new_user}, you need to enter new username!")
else:
print(f"{new_user}, This username is available.")
解决方案
for new_user in new_users:
for current_user in current_users:
if new_user.lower() == current_user.lower():
print('new user {} allready present'.format(new_user))
推荐阅读
- javascript - 使用 mui 反应表 - mui 厨房水槽示例 - 切换 JSON 和 makeDATA
- c++ - 类中类型“char text [100]”的探测器类型
- excel - 无法从 VBA 中的 MSXML2.IXMLDOMNodeList 变量中提取信息
- excel - 取不同列中的值以将它们收集到单个列下
- git - 如何在强制推送中激活 git hook post-receive?
- python - 如何更改 xarray 中的一个变量?
- authentication - OKTA - 为什么授权或端点端点不起作用?
- c# - 在 UIelementCollection 中移动项目
- javascript - 打开链接搜索然后关闭 javascript
- python - 从创建的类中获取所有字符串