Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: powershell bulk rename and add extra string to filename 
Python :: Amazing Trees with python turtle 
Python :: migrate database in django 
Python :: matplotlib force scientific notation and define exponent 
Python :: stripping whitespace in python 
Python :: DJANGO model instance get by variable 
Python :: are there learning activities for django-debug-toolbar 
Python :: python clear memory 
Python :: find the median of input number in a list and print 
Python :: python 3 documentation 
Python :: Print characters from a string that are present at an even index number 
Python :: python get global variable by name 
Python :: count unique values in python 
Python :: twitter scraping python 
Python :: how to add find the smallest int n in a list python 
Python :: python send email from icloud 
Python :: explode multiple columns pandas 
Python :: how to store something in python 
Python :: 151 problem solution 
Python :: django models filter 
Python :: python slicing a list 
Python :: pyad create user 
Python :: global /tmp/pip-req-build-civioau0/opencv/modules/videoio/src/cap_v4l.cpp (587) autosetup_capture_mode_v4l2 videoio(v4l2:/dev/video0): device is busy 
Python :: get raster corners python 
Python :: python get website chrome network tab 
Python :: python append 
Python :: aws django bucket setting 
Python :: python maximum product subarray 
Python :: np.zero 
Python :: how to print 0 to 10 in python 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =