Skip to content

Instantly share code, notes, and snippets.

@miku
Created January 3, 2011 15:34
Show Gist options
  • Select an option

  • Save miku/763574 to your computer and use it in GitHub Desktop.

Select an option

Save miku/763574 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# http://stackoverflow.com/questions/4585255/how-to-filter-all-words-which-contain-n-or-more-characters/4585315
import sys, re
def morethan(n, file_or_string):
try:
content = open(file_or_string, 'r').read()
except:
content = file_or_string
pattern = re.compile("[\w]{%s,}" % n)
return pattern.findall(content)
if __name__ == '__main__':
try:
print morethan(*sys.argv[1:])
except:
print >> sys.stderr, 'Usage: %s [COUNT] [FILENAME]' % sys.argv[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment