【问题标题】:How do I return true, for two arrays that are the same length and value? (Python)对于长度和值相同的两个数组,如何返回 true? (Python)
【发布时间】:2022-12-03 17:30:52
【问题描述】:

So, the question I am trying to solve is...

\"Return true if two arrays are equal.

The arrays are equal if they are the same length and contain the same value at each particular index.

Two empty arrays are equal.\"

for example:

input:

a == [1, 9, 4, 6, 3]
b == [1, 9, 4, 6, 3]

output: 
true

OR 

input:
a == [5, 3, 1]
b == [6, 2, 9, 4]

output:
false

This is how I went about it. I\'m able to get the length of the arrays right, but I don\'t know how to ensure the values in it will be the same too. That\'s the part I am stuck on how to implement.

def solution(a, b):
    if range(len(a)) == range(len(b)): 
        return True
    else: 
        return False

标签: python arrays python-3.x numpy


【解决方案1】:
猜你喜欢
  • 2011-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-22
  • 2018-09-09
  • 1970-01-01
  • 1970-01-01
  • 2020-09-24
相关资源
最近更新 更多