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 如何修复此问题:AttributeError:';列表';对象没有属性';下';在py3中?_Python 3.x - Fatal编程技术网

Python 3.x 如何修复此问题:AttributeError:';列表';对象没有属性';下';在py3中?

Python 3.x 如何修复此问题:AttributeError:';列表';对象没有属性';下';在py3中?,python-3.x,Python 3.x,我需要知道如何对此列表执行不区分大小写的操作?您需要将该方法应用于列表中的单个字符串,而不是列表本身 current_users = ['mohammad', 'shervin' , 'ali', 'oskol' , 'pro_gamer'] new_users = ['ali', 'ahmad', 'shervin', 'lara', 'helena'] current_users.lower() new_users.lower() for new_user in new_users: if

我需要知道如何对此列表执行不区分大小写的操作?

您需要将该方法应用于列表中的单个字符串,而不是列表本身

current_users = ['mohammad', 'shervin' , 'ali', 'oskol' , 'pro_gamer']
new_users = ['ali', 'ahmad', 'shervin', 'lara', 'helena']
current_users.lower()
new_users.lower()
for new_user in new_users:
if new_user in current_users:
        print(new_user + " You must change your user name.")
else:
print("user name is available")
更新

另一种方法是使用比您自己的循环更快的集合:

current_users = [user.lower() for user in current_users]
.lower()
只能应用于字符串

试试这个:

current_users = ['mohammad', 'shervin' , 'ali', 'oskol' , 'pro_gamer']
new_users = ['ali', 'ahmad', 'shervin', 'lara', 'helena']

# normalize and convert to sets
current_users = set(user.lower() for user in current_users)
new_users = set(user.lower() for user in new_users)

# use sets to make decisions
conflicts = current_users & new_users
print("users {} already exist".format(', '.join(conflicts)))
uniques = new_users - current_users
print("users {} are available".format(', '.join(uniques)))

这真的对我很有帮助,但你能告诉我如何在当前用户中检查新用户吗?像这样:如果“shervin”使用了“shervin”,那么“shervin”肯定不接受。嗯,你刚才是不是剪切并粘贴了我的修复程序?!再考虑一下吧。code>.lower()可以应用于具有
lower
方法的任何类<代码>列表没有,但其他人有。非常感谢你能告诉我如何在当前用户中使用新用户:如果“Shervin”使用“Shervin”必须不接受。既然你将“Shervin”降格为“Shervin”,你会明白的。这就是我所需要的。非常感谢你。很抱歉,我不能投票,因为我的名声不到15岁。
current_users = ['mohammad', 'shervin', 'ali', 'oskol', 'pro_gamer']
new_users = ['ali', 'ahmad', 'shervin', 'lara', 'helena']

current_users = [user.lower() for user in current_users]

for new_user in new_users:
  if new_user in current_users:
  print(new_user + " You must change your user name.")
else :
  print("user name is available")