0

Suppose, we have two strings a = "hello" b = "holel"

they have the same set of alphabet and what/ how the code should be if we want true if all the characters are present in the strings.[they both have same set of alphabet(non-recursive{eg: string1 = 'a' and string = 'aa' they should be same as there is one a in the first string and 2 a's in the second string})and instead of individually comparing each alphabet]

do we have to search the first index of string 1 and search all the indices of the string 2 continue the same process until the end of the string 1 ?....as python is the best in strings.Is there any simpler method to do so?

1 Answers1

3

Use set

>>> a = "hello"
>>> b = "holel"
>>> set(a)
set(['h', 'e', 'l', 'o'])
>>> set(b)
set(['h', 'e', 'l', 'o'])
>>> set(a) == set(b)
True
>>> 
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274