I want to extract the keys from the two dictionaries and divide only the same key into one dictionary again.

Asked 2 years ago, Updated 2 years ago, 89 views

// Use three dictionaries.
Output A > {'ACG': [0], 'CGT': [1], 'GTT': [2], 'TTC': [3], 'TCC': [4], 'CCG': [5], 'CGG': [6, 10, 15]}
Output B > {'AAT': [0], 'ATA': [1], 'TAT': [2], 'ATC': [3], 'TCC': [4], 'CCG': [5], 'CGA': [6]}
Fixed Output C > {'ACG': [0], 'CGT': [1], 'GTT': [2], 'TTC': [3], 'TCC': [4], 'CCG': [5], 'CGG': [6, 10]}

Desired output value

Output:

C_sample reference comparison target A_sample:

// Use three dictionaries.
Output C > {'ACG': [0], 'CGT': [1], 'GTT': [2], 'TTC': [3], 'TCC': [4], 'CCG': [5], 'CGG': [6, 10]}

C_sample reference comparison target B_sample:

// Use three dictionaries.
Output C > {'TCC': [4], 'CCG': [5]}

B_sample reference comparison target C_sample:

// Use three dictionaries.
Output B > {'TCC': [4], 'CCG': [5]}

A_sample reference comparison target C_sample:

// Use three dictionaries.
Output A > {'ACG': [0], 'CGT': [1], 'GTT': [2], 'TTC': [3], 'TCC': [4], 'CCG': [5], 'CGG': [6, 10, 15]}

python dictionary list

2022-09-20 21:40

1 Answers

{k:C[k] for k in (set(B) & set(C))}

{'TCC': [4], 'CCG': [5]}


2022-09-20 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.