How do I compare two strings in python if order does not matter?

python, python-2.7, string, string-comparison

Solution

Seems question is not about strings equality, but of sets equality. You can compare them this way only by splitting strings and converting them to sets:

s1 = 'abc def ghi'
s2 = 'def ghi abc'
set1 = set(s1.split(' '))
set2 = set(s2.split(' '))
print set1 == set2

Result will be

True

Problem

I have two strings like ``` string1="abc def ghi" ``` and ``` string2="def ghi abc" ``` How to get that this two string are same without breaking the words?

Original source