python - What is the correct keyword for this line of code? -


the purpose of code extract number text file assigned variable called 3;

the code:

with open(three) f:     the_list = [int(l.strip().split()[1]) l in f] 

can explain reason why text file abbreviated letter 'f'. , the_list = [int(l.strip().split()[1]) l in f]

it's short name. can use valid name want following as keyword. here, short, one-letter name used because there no need emphasize name of file object is.

the second line creates list of integers stored in second field of each line of file. input file looks like

foo 3 hello 17 whatever 0 

which produces list like

[3, 17, 0] 

(l.strip() removes leading , trailing whitespace line; split() creates list consisting of whitespace-separated fields, indexed grab second field; , result passed int produce int object string.)


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -