“Leer Fichero de Texto Con Columnas Como Diccionario Python” Kod odpowiedzi

Leer Fichero de Texto Con Columnas Como Diccionario Python

def get_pair(line):
    key, sep, value = line.strip().partition(" ")
    return int(key), value

with open("file.txt") as fd:    
    d = dict(get_pair(line) for line in fd)
Better Bee

Leer Fichero de Texto Con Columnas Como Diccionario Python

d = {}
with open("file.txt") as f:
    for line in f:
       (key, val) = line.split()
       d[int(key)] = val
Better Bee

Odpowiedzi podobne do “Leer Fichero de Texto Con Columnas Como Diccionario Python”

Pytania podobne do “Leer Fichero de Texto Con Columnas Como Diccionario Python”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu