How to check If Two String Arrays are Equivalent or not?

By Albert, 2 months ago
  • Bookmark
0

Given two string arrays str1 and str2, return true if the two arrays represent the same string, and false otherwise.

A string is represented by an array if the array elements concatenated in order forms the string.

Array
String
Python
1 Answer
0

Following function check If Two String Arrays are Equivalent or not?


# two for loops: redundant
 
def string_equivalent(str1,str2):
   new_1 = "" # data type has to be a string
   new_2 = ""
   for i in str1:
       new_1+=i
   for j in str2:
       new_2+=j
   return new_1==new_2
 
# test case
str1 = ["xy", "z"]
str2 = ["x", "yz"]
string_equivalent(str1,str2)


output

True

Your Answer

Webinars

More webinars

Related Discussions

Running random forest algorithm with one variable

View More