Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.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中在列表中出现两次的元素的If语句_Python - Fatal编程技术网

Python中在列表中出现两次的元素的If语句

Python中在列表中出现两次的元素的If语句,python,Python,在Python中,我有两个坐标列表,如[(2,4),(4,5)]。一个用10个坐标填充,另一个为空。我有代码,所以如果玩家输入的坐标是数组。它将坐标附加到空数组中,该数组将表示“已访问”坐标。我想要一个if语句,它将检查“坐标”元素是否在“访问”列表中出现两次 def corcheck(coordinate,+10locations,+10visits,losecoinslocations,coins): if coordinate in +10locations: co

在Python中,我有两个坐标列表,如[(2,4),(4,5)]。一个用10个坐标填充,另一个为空。我有代码,所以如果玩家输入的坐标是数组。它将坐标附加到空数组中,该数组将表示“已访问”坐标。我想要一个if语句,它将检查“坐标”元素是否在“访问”列表中出现两次

def corcheck(coordinate,+10locations,+10visits,losecoinslocations,coins):
    if coordinate in +10locations:
        coins=coins+10
        coordinate.append(+10visits)
        print("+10")
#        if coordinate in
    elif coordinate in losecoinslocations:
        coins=0
        print("You lose all your coins. -",coins)
    else:
        print("This square was empty. Please make your next move.")
    return +10visits,+10num,losecoinsnum,coins
用#编辑的行是检查坐标元素是否在+10访问中出现两次的位置,从那里它将被附加到位置

if len(coordinate ) != len(set(coordinate )):

如果+10位置的坐标:是无效语法,则set将删除重复项,并根据原始列表检查长度
10位置
10访问
不是有效的python标识符…找不到重复的,它太基本了…可能重复的请澄清问题:您需要知道是否存在任何重复的元素,或者哪些元素是重复的吗?如果一个元素出现3或4次,您需要该数量吗?