As you attach two Python Dictionaries to another dictionary

0

I'm new to Python

but I have a matrix of several columns column 0 has (01/02/18 to 02/28/1) the column in column 2 I have ('8-6 ENL TIC-DZT', '4-2 ENL PLD-STA-NRI ',' 6-12 ENL ALT-TMO ',' _0-16 MALPASODOS-TABASCO ',' 3-1 ENL MAN ',' 4-7 CHO 400-230 ',' 4-10 SCP- HGA ',' 8-9 ENL VAD-CNC ',' 2-2 ENL LAV-TCL LAV-PBD ',' _0-4 ENL LCP_PIT DOG CRP ',' _0-22 ENL HERMOSILLO-SIN ',' 8-10 ENL)

dic_Enlace={}
dic_Fecha={}

   for i in range(len(HST)):
    dic_Fecha[HST[i][0]]={}
    #print dic_Fecha

    for j in range(len(HST)):
    dic_Enlace[HST[j][2]]={}
    #print dic_Enlace

I wanted to put these two dictionaries to the next dic_MEM

    
asked by Horacio 16.02.2018 в 18:37
source

1 answer

1

The functionality of a dictionary in python is that of key - > value, that is, each key (the keys can not be lists or dictionaries) is assigned a value (which can be anything, even another dictionary, in fact, a value stored in a dictionary can be itself).

If I understood well what you want to do (it would be useful to add more information, as you already commented, your question is incomplete), one way to better organize the information would be:

{
  FECHA1: [
    HORA1,
    HORA2,
    HORA3,
  ],
  FECHA2: [
    HORA1,
    HORA2,
    HORA3,
  ],
}

An example of this format would be:

{
  "01/02/2018": [
     "8-6 ENL TIC-DZT",
     "4-2 ENL PLD-STA-NRI",
  ],

  "05/02/2018": [
    "2-2 ENL LAV-TCL LAV-PBD",
    "_0-22 ENL HERMOSILLO-SIN',
  ],
}

To generate a dictionary with this structure from the information as you have it:

informacion = {}

for i in range(len(HTS)):
    informacion[HST[i][0]] = []  # Creamos la lista con la informacion asociada a la fecha

    for hora in HTS[i][2]:
        informacion[HST[i][0]].append(hora)  # Agregamos las horas a la lista recien creada

Obviously you can work with the two dictionaries as you have been doing. To "add" that information to the dic_MEM dictionary:

If you work with a dictionary:

dic_MEM["informacion"] = informacion  # El diccionario del ejemplo
print(dic_MEM["informacion"])  # Con 'dic_MEM["informacion"]' podras acceder al diccionario con toda la informacion

If you work with two dictionaries:

dic_MEM["enlaces"] = dic_Enlaces
dic_MEM["fechas"] = dic_Fechas
print(dic_MEM["enlaces"])  # Con 'dic_MEM["enlaces"]' podras acceder a dic_Enlaces
print(dic_MEM["fechas"])  # Con 'dic_MEM["fechas"]' podras acceder a dic_Fechas

Again, it is not very clear what you want to get (the output) or what is the purpose of 'Dec_Links', so this answer may not fit all you're looking for.

    
answered by 18.02.2018 в 22:09