Skip to content

Instantly share code, notes, and snippets.

@rbrito
Created January 29, 2013 02:36
Show Gist options
  • Save rbrito/4661238 to your computer and use it in GitHub Desktop.
Save rbrito/4661238 to your computer and use it in GitHub Desktop.
#!/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'))
else:
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