Creating an array in Python while conserving line format -
Creating an array in Python while conserving line format -
i have file in next format style:
unitig_19 <tab> . <tab> part 13221 13240 0.00 + <tab> . <tab> cov2=..... unitig_19 <tab> . <tab> part 13241 13260 0.00 + <tab> . <tab> cov2=..... unitig_19 <tab> . <tab> part 13261 13280 0.00 + <tab> . <tab> cov2=.....
and on.
how can create array while conserving format , not having info jammed 1 massive line? this:
[unitig_19, ., region, 13221, 13240, 0.00, +, ., cov2=.....] [unitig_19, ., region, 13241, 13260, 0.00, +, ., cov2=.....] [unitig_19, ., region, 13261, 13280, 0.00, +, ., cov2=.....]
my goal afterwards extract specific pieces each line array.
any help appreciated!
you can utilize regex re.split
function :
>>> s="""unitig_19 <tab> . <tab> part 13221 13240 0.00 + <tab> . <tab> cov2= ... unitig_19 <tab> . <tab> part 13241 13260 0.00 + <tab> . <tab> cov2= ... unitig_19 <tab> . <tab> part 13261 13280 0.00 + <tab> . <tab> cov2=""" >>> import re >>> [[i in j if i] j in [re.split(r'<.*?>| {1,}',line) line in s.split('\n')]] [['unitig_19', '.', 'region', '13221', '13240', '0.00', '+', '.', 'cov2='], ['unitig_19', '.', 'region', '13241', '13260', '0.00', '+', '.', 'cov2='], ['unitig_19', '.', 'region', '13261', '13280', '0.00', '+', '.', 'cov2=']]
note if <tab>
's \t
need alter <.*?>
in pattern \t
.
python arrays
Comments
Post a Comment