How do i covert this into a Python code. I dont get how to do the compare between players and the winNum. The players is a 2D array and winNum is a 1D array.
below is a sample data set that i have been using
in the function what im trying to achive is that for every player in players i want to compare all their numbers with the winNum numbers and find if they match and if they do match i want to make 1 increment to the count. Both arrays have 8 elements and they are sorted from 0-6 and 6-8.
winNum = [0, 5, 20, 22, 23, 25, 0, 26]
player = [[0, 5, 20, 22, 23, 25, 0, 26],[14, 15, 21, 25, 26, 29, 30, 30],[3, 6, 8, 16, 25, 30, 0, 13]]
for i in range (len(player)):
for j in range(6):
x = player[i][j]
and compare with winNum[](0-6)
if x is in winNum:
count +=c1
and move on to the next number
else
ignore and move on to the next number
You could try the following code:
count=0
for i in range(len(player)):
for j in range(8):
x = player[i][j]
if x in winNum:
count+=1
You could also store the 'count' further by appending it to a new empty list. I wasn't sure if you wanted that too, but doing that is also straight forward.
count_list = []
for i in range(len(player)):
count=0
for j in range(8):
x = player[i][j]
if x in winNum:
count+=1
count_list.append(count)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.