Compare string like ‘1,2,3’ and ‘3,1,2’ to be set as equals in Python [closed]

Tags: , , , ,



I have a strings like ‘1,2,3’ and ‘3,1,2’in a list, is there any way to compare these two strings and check that they are the same?

I have a lis a = [‘G1G2G3,G4,G10’,’G4,G1G2G3,G10], i need a[0] == a[1] to return TRUE

Answer

Convert each string to a set, and compare the results.

>>> set('1,2,3'.split(',')) == set('3,1,2'.split(','))
True


Source: stackoverflow