Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. # finding the content of parenthesis that occurs after a square bracket set
  2. text = """i dont know [TOP of the mind recall] This stuff.
  3. Regarding anti only, (kenan Devan)
  4. blah [blah] blah (KENAN Stinger) [TOP of the mind recall] This stuff.
  5. Regarding anti only, (kenan Devan)
  6. blah [blah] blah (Steve roger) [lucknow] where i live (226001)"""
  7. sqrbrack_pos = []
  8. pos = 0
  9. for i in range(text.count(']')):
  10. sqrbrack_pos.append(text.find(']',pos))
  11. pos = sqrbrack_pos[i]+1
  12.  
  13. round_brack = {}
  14. for i,pos in enumerate(sqrbrack_pos):
  15. openp = text.find('(',pos+1)
  16. closep = text.find(')',openp+1)
  17. round_brack.update({f'{i+1}':[openp+1,closep]})
  18.  
  19. for pos,coords in round_brack.items():
  20. print(f'{pos} found {text[coords[0]:coords[1]]} ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement