regex - Code review - Simple Mnemonic generator in python -


I'm looking at some dragon code review - this code takes a string of digits and generates a reminder To memorize the words (this is using the main system, but with the encoding of Darren Brown) It does this by running egrep on a regular expression and system level.

I am looking for a way to improve codes or algorithms (and in the form of cruelty) (I know that comments should be) - I am an entertaining dragon programmer and would like to improve my skills If you tell a great way to get a dragon out of the dragon to bring it, then it will be very good

  #! / Usr / bin / python Import System Import Import OS F = "[wcaeiouy]?" Expression = str ("^" + f + sys.argv [1]) expression = expression. Location ("1", "L" + F) expression = expression. Place ("2", "N" + F) expression expression = expression. Position ("5", "[FV]" + F) expression = expression = reset ("3", "m" + f) expression = expression Place ("4", "R" + F) expression = expression = Expression. Location ("6", "[PB]" + F) Expression = expression. Location ("7", "T" + F) expression = expression. Location ("8", "[scan] H" + F) expression = expression.replace ("9", "[gd]" + f) expression = expression.replace ("0", "[zs]" + f ) Expression = 'egrep' + Expression + 'words.txt' Os.system (expression)    

You can replace many repetitive tasks:

  expression = str ("^" + f + sys.argv [1]) expression = expression.replace ("1" , "L" + f) expression = expression.replace ("2", with "chained method call   

:

  expression = str (" ^ "+ F + sys.argv [n] 1]) .replace (" 1 "," l "+ f) \ .replace (" 2 "," n "+ f) (...)   

\ s They should not have any letters after this, it is not giving any speed, of course, but the code looks good.

The coded grape in Python looks like this: < Pre: import re regexp = open with recompile (expression) as f (for 'words.txt', 'r') f: for word f.read (). Split ('\ t \ n '): If regexp.match (words): print word

Comments