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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -