Python создать конкретный дикт из трех списков

В C ++ операторы (для типов POD) всегда действуют на объекты того же типа. Таким образом, если они не совпадают, то они будут повышаться в соответствии с другими. Тип результата операции совпадает с типом операндов (после преобразования).

If either is      long          double the other is promoted to      long          double
If either is                    double the other is promoted to                    double
If either is                    float  the other is promoted to                    float
If either is long long unsigned int    the other is promoted to long long unsigned int
If either is long long          int    the other is promoted to long long          int
If either is long      unsigned int    the other is promoted to long      unsigned int
If either is long               int    the other is promoted to long               int
If either is           unsigned int    the other is promoted to           unsigned int
If either is                    int    the other is promoted to                    int
Both operands are promoted to int

Примечание. Минимальный размер операций - int. Таким образом, short / char продвигаются до int до выполнения операции.

Во всех ваших выражениях int до выполнения float до выполнения операции. Результатом операции является float.

int + float =>  float + float = float
int * float =>  float * float = float
float * int =>  float * float = float
int / float =>  float / float = float
float / int =>  float / float = float
int / int                     = int
int ^ float =>  <compiler error>
3
задан locklockM 18 January 2019 в 09:55
поделиться

3 ответа

Как насчет

for a,b,c in zip(A, B, C):
    your_dict[c] = {"name" : a, "age": b} 
0
ответ дан ApprenticeHacker 18 January 2019 в 09:55
поделиться

Если вы не хотите использовать zip, вы можете использовать enumerate, как указано ниже:

print ({v:{"name": A[k],"age": B[k]} for k, v in enumerate(C)})
0
ответ дан Akash Swain 18 January 2019 в 09:55
поделиться
In[1]:  {c: {'name': a, 'age': b} for a, b, c in zip(A, B, C)}
Out[1]: {'key1': {'name': 'a', 'age': '10'}, 'key2': {'name': 'b', 'age': '20'}}
0
ответ дан Ghilas BELHADJ 18 January 2019 в 09:55
поделиться
Другие вопросы по тегам:

Похожие вопросы: