小编Pha*_*est的帖子

Python, list of tuples split into dictionaries

I have a list of tuples as shown:

lt = [(1,'a'),(1,'b'),(2,'a'),(3,'b'),(3,'c')]
Run Code Online (Sandbox Code Playgroud)

I want to make the numbers keys of a dictionary and have them point to a list. That list then holds all associations in the list of tuples. So in the list above, it would split into a dictionary as:

dict_lt:{
1:[a,b],
2:[a],
3:[b,c]
}
Run Code Online (Sandbox Code Playgroud)

Currently I use the dictionary's flexibility in automatically declaring new keys, which I then force point to an empty list. Then I fill that …

python dictionary tuples list

5
推荐指数
1
解决办法
78
查看次数

Using a #define in a formatted printf to define precision

#include <stdio.h>
#define PREC 4

int main()
{
    long l = 12;
    printf("%PRECld", l);
}
Run Code Online (Sandbox Code Playgroud)

我将如何使用它PREC来定义所需的精度?即预期的产出是0012。目前正在印刷%PRECld

c printf

4
推荐指数
1
解决办法
71
查看次数

标签 统计

c ×1

dictionary ×1

list ×1

printf ×1

python ×1

tuples ×1