Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import string
import re
INPUT_FILE = 'balanced_smileystxt.txt'
input = open(INPUT_FILE, 'r')
count = input.readline()
for i in range(int(count)):
balanced_characters = set(string.ascii_lowercase)
balanced_characters.add(' ')
line = input.readline().strip()
line = ''.join(c for c in line if c not in balanced_characters)
p = re.compile('\(?(:\)|:\(|:)*\)?')
m = p.match(line)
if m and (m.end() - m.start() == len(line)):
print('Case #%d: %s' % (i + 1, 'YES'))
print('Case #%d: %s' % (i + 1, 'NO'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment