How to manipulate strings in Python?

0 votes
I have a string s with nested brackets: s = "BN(m>o)&Q((-i)Tw)". I want to remove all characters between all pairs of brackets and store in a new string like this: new_string = BN&Q. How to do this in Python?
Aug 9 in Python by Neel
• 3,010 points
27 views

1 answer to this question.

0 votes

This can be done is a very simple way. You can refer to the following code snippet.

s = "BN(m>o)&Q((-i)Tw)"
>>> [ i.split("(")[0] for i in s.split(")") ]
['BN', '&Q', 'Tw', '']
>>> 
answered Aug 9 by Arvind
• 2,960 points

Related Questions In Python

0 votes
1 answer

How to format strings in python?

To answer your first question... .format just seems more ...READ MORE

answered Oct 1, 2018 in Python by ariaholic
• 7,340 points
40 views
0 votes
1 answer

How to calculate time interval between two time strings in Python

Try doing this - It is efficient for ...READ MORE

answered Nov 29, 2018 in Python by Nymeria
• 3,520 points

edited Dec 11, 2018 by Nymeria 194 views
0 votes
1 answer

how to compare two strings in python?

compare two string in python >>> s1="abc ...READ MORE

answered Mar 25 in Python by rajesh
• 1,210 points
53 views
+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,720 points
3,036 views
+4 votes
6 answers
0 votes
1 answer

Removing surrounding whitespace

Try the strip() function:  s = s.strip() If you ...READ MORE

answered May 4, 2018 in Python by Nietzsche's daemon
• 4,260 points
56 views
+1 vote
1 answer

How to install a module in Python 3.6 ?

If you are using Ubuntu then the ...READ MORE

answered Jun 25 in Python by Arvind
• 2,960 points
97 views
+1 vote
1 answer

How to convert records from csv to a list in Python?

If you are using Python 3.x then ...READ MORE

answered Jun 25 in Python by Arvind
• 2,960 points

edited Jun 26 by Kalgi 59 views