Skip to content
Advertisement

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

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

Advertisement

Answer

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

>>> set('1,2,3'.split(',')) == set('3,1,2'.split(','))
True
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement