1

I am trying to code a function where it compares all the strings within a list and checks if they are equivalent to another with the checking statement. I want the answer to be True if 2 or more strings are equivalent if not False. How would i be able to modify checking so that it works with numpy arrays instead of a normal list.

Code:

import numpy as np 

def Checker(reader):
    checking = any(s for s in set(reader) if reader.count(s) > 1)
    print(checking)

reader = np.array(["cat", "dog", "cheetah", "giraffe", "monkey"])
reader2 = np.array(["cat", "dog", "cat", "giraffe", "monkey"])
reader3 = np.array(["cat","cheetah", "monkey"])

result = Checker(reader)
result2 = Checker(reader2)
result3 = Checker(reader3)

Error:

AttributeError: 'numpy.ndarray' object has no attribute 'count'

The result should list:

False
True
False
1
  • 1
    Very juicy question 👍👍👍👍 senpai Commented May 17, 2021 at 21:08

1 Answer 1

2

TRY:

def Checker(reader):
    return np.unique(reader).size != reader.size
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.