擅长:python、mysql、java
<pre><code>data = {
'jan': ['John Smith', 'Cat Stevens', 'Andrew Alexander', 'El Gordo Baba'],
'feb': ['Louis le Roy', 'John Smith'],
'mar': ['Cat Stevens', 'Louis le Roy']
}
subs = {}
unsubs = {}
for mon in data:
for name in data[mon]:
if name not in subs:
subs[name] = mon
else:
unsubs[name] = mon
>>> subs
{'Andrew Alexander': 'jan', 'Louis le Roy': 'mar', 'John Smith': 'jan', 'El Gordo Baba': 'jan', 'Cat Stevens': 'jan'}
>>> unsubs
{'Louis le Roy': 'feb', 'John Smith': 'feb', 'Cat Stevens': 'mar'}
</code></pre>