Question

I have the following code:

#Write the lines back which do NOT match the command
for line in lines:
    if line != command:
        file_writer.write(line)

And two example Strings I have are:

lines = [
    """user_operations.add_user("url",531,{u'Username': u'TEST123567', u'Status': u'Enabled', u'AccessTypes': [u'APN'], u'Auth': u'ServicePassword', u'ID': 7400, u'PasswordInfo': None, u'SSOInfo': None, u'Email': u'', u'AccountID': 531},False,headers)""",
    """user_operations.add_user("url",531,{u'Username': u'TEST123567', u'Status': u'Enabled', u'Email': u'', u'PasswordInfo': None, u'AccessTypes': [u'APN'], u'AccountID': 531, u'ID': 7400, u'Auth': u'ServicePassword', u'SSOInfo': None},False,headers)"""
]

Is there any quick 'n' dirty function to check if they contain the same data regardless of the order?

Thanks!

Was it helpful?

Solution

Assuming that you are getting a list of strings in lines, the following code should work:

#Write the lines back which do NOT match the command
sorted_command = sorted(command)
for line in lines:
    if sorted(line) != sorted_command:
        file_writer.write(line)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top