Advertisement
marcosthomazs

Detectando Tokens

Jan 26th, 2021
1,344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def recebe_seq(vetor):
  2.     aux = []
  3.     tokens = {']': '[', '}': '{', ')': '('}
  4.     for i in vetor:
  5.         if i in tokens.values():
  6.             aux.append(i)
  7.         else:
  8.             if len(aux) == 0 or tokens[i] != aux[-1]:
  9.                 return False
  10.             aux = aux[:-1]
  11.     return len(aux) == 0
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement