python compare tuples and dictionary
Question: I have to compare two sets and find the differences in python:

    
    
    >>> mysql_orders = ((50434L, 5901L), (50733L, 5901L))
    >>> opera_orders = [{'orderId': 'WEB050434', 'accountId': '00T001'}, {'orderId': 'WEB050733', 'accountId': '00T001'}, {'orderId': 'DOC075185', 'accountId': '00T001'}, {'orderId': 'WEB081859', 'accountId': '00T001'}]
    

One is a list of tuples and the other a list of dictionaries where the first
item in the list could be the `orederId` without the WEB / DOC prefix.

What is the correct way to find the missing orderId's that are not in
mysql_orders list?


Answer: If the letters may or may not be there but the leading 0 is always there you
can use a set a strip:

    
    
    from string import ascii_letters
    
    st = set(str(a) for a,_ in mysql_orders)
    
    missing = [d['orderId'] for d in opera_orders if not d['orderId'].strip(ascii_letters)[1:] in st]
    
    print(missing)
    
    ['DOC075185', 'WEB081859']
    

If the prefix is always there just slice:

    
    
    missing = [d['orderId'] for d in opera_orders if not d['orderId'][4:] in st]
    

