User Profile
Collapse
-
i am just learning python so some obvious things i are not so obvious to me. for that project i ended up making two opens for the same file but as of now i have updated myself on how and when to use for loops. thanks. -
i realize i the while statement reads it once everytime the loop goes through thus skipping the line. sorry for waste.Leave a comment:
-
david2031 started a topic (python) for some reason file.readline() is only reading every second linein Python(python) for some reason file.readline() is only reading every second line
why is this skipping readlines in what it returns? i went through debugger and found it thinks the second line of the txt file is the first and continues to skip every second line.
Code:def get_distances(filename): opener = open(filename) d = {} while file.readline(opener) != '': '''converts a file with cities and distances into a dictionary with values of distances from one city to
-
the str.split(sep,maxsplit) function
given:
my = 'my name is david'
i would like to make this into a list with 2 values
i would like the list to be:
mylist = ['my name is','david']
so i try using:
mylist = my.split(' ',1)
but i soon find it splits left to right which returns:
mylist = ['my','name is david']
to avoid having to use alot of other code, i am wondering if there is a way to make it split right...
No activity results to display
Show More
Leave a comment: