1
1
1vple2021-12-03 21:27:41
Python
1vple, 2021-12-03 21:27:41

How to remove extra characters?

 Hello! There is a file with two such lines:

***ba*** *imen.* SUM^3^ Orf-9 BN F^2^ Gr Goal UNS^2^ UAS URS
**ba^1^** *vig .* SUM (*res.*) Orff-9 BN F Gr UNS UAS URS (*res.*)

I break each into 3 parts: what is in the first asterisks, what is in the second and what starts with SUM
So I remove the asterisks in the second part, since there are always two of them:

r = []
for i in file:
 s = i.split(" ")[0]
 o = " ".join(i.split(" ")[1:])
 try:
  ch = o.split("*")[1]
  o = o.replace(ch,"").replace("**","")
 except:
  ch = None
 r.append([s,ch,o])


I get the following:
['***ba***', imen., 'SUM^3^ Orf-9 BN F^2^ Gr Goal UNS^2^ UAS URS'],
['**ba^1^* *', 'vig.', ' SUM (*diff.*) Orf-9 BN F Gr UNS UAS URS (*diff.*)']

It is necessary to have
['ba', imeni, 'SUM^3^ Orf-9 BN F^2^ Gr Gol UNS^2^ UAS URS'],
['ba^1^', 'vig.', ' SUM (*size*) Orf-9 BN F Gr UNS UAS URS ( *diff.*)']

How can you remove all * in the first part, if there are 4 or 6 of them? Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question