문제

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!

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top