我有以下代码:
#Write the lines back which do NOT match the command
for line in lines:
if line != command:
file_writer.write(line)
我有两个字符串示例:
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)"""
]
是否有任何快速'n'脏函数来检查它们是否包含相同的数据而不管订单是什么?
谢谢!
答案 0 :(得分:2)
假设您在lines
中获得了一个字符串列表,则以下代码应该有效:
#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)