I've got a dictionary with data of the same length (but different types), something like:
data = {
"id": [1,1,2,2,1,2,1,2],
"info": ["info1","info2","info3","info4","info5","info6","info7","info8"],
"number": [1,2,3,4,5,6,7,8]
}
Now I'd like to split it in two by id
, keeping the respective info
and number
. That is, to have two dicts data1
and data2
.
Note: this is merely a sample, there are multiple keys in the dict and I would want to avoid using the key names, but rather loop through all of them.
What is a Pythonic way of doing it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…