Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # finding the content of parenthesis that occurs after a square bracket set
- text = """i dont know [TOP of the mind recall] This stuff.
- Regarding anti only, (kenan Devan)
- blah [blah] blah (KENAN Stinger) [TOP of the mind recall] This stuff.
- Regarding anti only, (kenan Devan)
- blah [blah] blah (Steve roger) [lucknow] where i live (226001)"""
- sqrbrack_pos = []
- pos = 0
- for i in range(text.count(']')):
- sqrbrack_pos.append(text.find(']',pos))
- pos = sqrbrack_pos[i]+1
- round_brack = {}
- for i,pos in enumerate(sqrbrack_pos):
- openp = text.find('(',pos+1)
- closep = text.find(')',openp+1)
- round_brack.update({f'{i+1}':[openp+1,closep]})
- for pos,coords in round_brack.items():
- print(f'{pos} found {text[coords[0]:coords[1]]} ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement