Many-to-one mapping (creating equivalence classes)

后端 未结 4 769
花落未央
花落未央 2020-12-31 07:08

I have a project of converting one database to another. One of the original database columns defines the row\'s category. This column should be mapped to a new category in t

4条回答
  •  旧巷少年郎
    2020-12-31 08:12

    >>> monty={ ('parrot','spam','cheese_shop'): 'sketch', 
            ('Cleese', 'Gilliam', 'Palin') : 'actors'}
    
    >>> item=lambda x:[z for y,z in monty.items() if x in y][0]
    >>>
    >>> item("parrot")
    'sketch'
    >>> item("Cleese")
    'actors'
    

    But let me tell you, It will be slow than normal one to one dictionary.

提交回复
热议问题