简体   繁体   English

如何在python上检查两个列表是否相等

[英]How can I check if two lists are equal to one another on python

I'm developing a code breaker game where the user is given a coded list and the user has to guess what letter each symbol represents. 我正在开发一个破码游戏,其中给了用户一个编码列表,用户不得不猜测每个符号代表什么字母。 When the user thinks he has replaced all of the symbols with the correct letters he/she would then type 'check'. 当用户认为他已用正确的字母替换了所有符号后,他/她将输入“ check”。 What I want my check function to do, is to compare the users list with a separate list with the correct answers but I am stuck on how to do so. 我希望我的检查功能要做的是将用户列表与具有正确答案的单独列表进行比较,但是我仍然坚持这样做。

Just use the == operator, it calls the method __eq__ on the list which check the elements equality: 只需使用==运算符,它将调用列表中的__eq__方法来检查元素的相等性:

>>> a = [1, 2, 3]
>>> b = [1, 2, 3]
>>> c = [1, 2, 3, 4]
>>> a == b
True
>>> a == c
False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM