python - Reading selected portion of line and soting it in array -
how read every line of string in python , store seleted line element in array?
i want read file line line , each line appended end of array. not find how anywhere , couldn't find how create array of strings in python.
for example:
line1=
abc def gef lmn qrt lmh kjd lxm skd fdj djk ndz weg tdg ndg has dbg pef rah vdg pas dgh ghr bde ghx ore
my output should be:
line1[0]= abc def gef lmn qrt lmh kjd lxm line1[1]= skd fdj djk ndz weg tdg ndg has dbg line1[2]= pef rah vdg pas dgh ghr bde ghx ore
>>> line1 = """abc def gef ... lmn qrt ... lmh kjd lxm ... ... skd fdj djk ... ndz weg tdg ... ndg has dbg ... ... pef rah vdg ... pas dgh ghr ... bde ghx ore""" >>> line1.split("\n\n") ['abc def gef\nlmn qrt was\nlmh kjd lxm', 'skd fdj djk\nndz weg tdg\nndg has dbg', 'pef rah vdg\npas dgh ghr\nbde ghx ore'] >>> number, item in enumerate(line1.split("\n\n")): ... print("line number {0}".format(number)) ... print(item) ... line number 0 abc def gef lmn qrt lmh kjd lxm line number 1 skd fdj djk ndz weg tdg ndg has dbg line number 2 pef rah vdg pas dgh ghr bde ghx ore >>>
Comments
Post a Comment