- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
current_users = ['Andy', 'Brett', 'Cassie', 'Derek', 'Eric']
new_users = ['eric', 'greg', 'hank', 'ian', 'john', 'andy', 'frank']
new_users.sort()
for current_user in current_users:
current_user = current_user.lower()
for new_user in new_users:
if new_user == current_user:
print(f"\n{new_user}, Please enter a new username!")
else:
print(f"\n{new_user}, Username is available.")
由于用户名可用,Andy 正在被打印。另外请帮我简化一下,因为我刚刚学习 python。
最佳答案
您可以使用列表理解将current_users
中的用户名转换为小写
。其次,您必须检查 new_user
是否已存在于 current_users
中,为此您必须使用 in
关键字。
in
关键字tests whether or not a sequence contains a certain value.
这是代码,
current_users = ['Andy', 'Brett', 'Cassie', 'Derek', 'Eric']
new_users = ['eric', 'greg', 'hank', 'ian', 'john', 'andy', 'frank']
new_users.sort()
current_users = [user.lower() for user in current_users]
for new_user in new_users:
if new_user in current_users:
print(f"\n{new_user}, Please enter a new username!")
else:
print(f"\n{new_user}, Username is available.")
希望对你有帮助!
关于python - 为什么不打印字符串 'andy' 请输入新用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60312954/
我在打开后安装 andy andriod 模拟器我有错误操作被取消 (10) 并单击 [确定] 后自动关闭。 请帮助修复它。 我的显卡更新到最新版本 最佳答案 我遇到了同样的问题。根据 Nauman,
current_users = ['Andy', 'Brett', 'Cassie', 'Derek', 'Eric'] new_users = ['eric', 'greg', 'hank', 'i
当我启动我的android时出现这个错误 安迪错误 无法启动 VM 进程:虚拟机“andy”已终止意外地在启动过程中 1a64.1a20: Log file opened: 4.3.28r100309
我已经看过这个问题,但仍然找不到代码中的错误。我使用 Dreamweaver 的自动化功能来执行此操作,因此我根本不明白为什么会收到错误。 我的login.php页面上的代码是: if (!i
我有一个使用 Andy McCurdy 的 python 库的 python 加载器,它打开多个 Redis 数据库连接并设置数百万个键循环遍历行文件,每行包含一个整数,该整数是该记录的 redis-
我们正在尝试在 Objective-C 实现中引用 Swift 方法。 swift 类: import Foundation @objc class MySwiftClass: NSObject {
我正在尝试通过监视 Andy 模拟器上的出站/入站 HTTP 流量来在应用程序 (Android) 上进行调试 session 。对于 SSL 流量,我收到以下错误: 失败:SSLHandshake:
我是一名优秀的程序员,十分优秀!