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, 2019 in Python by Neel
• 3,020 points
409 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, 2019 by Arvind
• 3,040 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 aryya
• 7,450 points
526 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,560 points

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

how to compare two strings in python?

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

answered Mar 25, 2019 in Python by rajesh
• 1,270 points
905 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
14,787 views
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,474 views
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
575 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, 2019 in Python by Arvind
• 3,040 points
963 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, 2019 in Python by Arvind
• 3,040 points

edited Jun 26, 2019 by Kalgi 9,546 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP