x = {'a': ['aaa', 'bbb'], 'b': ['aaa', 'ccc'], 'c': ['bbb', 'ccc']}
y = []
for i in x['a']:
if i in x['c']:
y.append(i)
print(y)
If you write it like this, only ["bbb"] comes out I want to print 'a' and 'c' to which 'bbb' belongs. For example, 'a', 'c' : [bbb] Like this.
And I checked only 'a', the key value of one of the dictionary x in the for statement, but I want to check all of them by putting x, so how can I compare and express all of them?
(I made 3 combinations of 2 using cobinations, but I failed because I couldn't access the value.)
Please give me some advice. Thank you.
Desired output value
'aaa' : 'a', 'b'
'bbb' : 'a', 'c'
'ccc' : 'b', 'c'
python list dictionary
>>> x = {'a': ['aaa', 'bbb'], 'b': ['aaa', 'ccc'], 'c': ['bbb', 'ccc']}
>>> all_val = set(x['a']) | set(x['b']) | set(x['c'])
>>> all_val
{'aaa', 'ccc', 'bbb'}
>>> for e in sorted(all_val):
ks = [ k for k, v in x.items() if e in v ]
if ks:
print('%s : %s'%(e, ', '.join(ks)))
aaa : a, b
bbb : a, c
ccc : b, c
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.