Skip to main content
deleted 180 characters in body
Source Link
Daniel
  • 4.6k
  • 2
  • 18
  • 40

I haven'tdon't have time to fully review all of your code (at least for now), but here's some recommendations:

  • If I'm not mistaken, xrange() starts at 0 if no first argument is given (this is the case with range() in Python 3). So unless you need to start at another initial value, leave out the first argument and just call xrange(end<upper bound>). The same goes for random.randrange(), by the way.

  • Some of your variable names are bad (non-descriptive)not descriptive. EspeciallyIn particular dictionary1 and dictionary2, among othersand (all_chars2). As I didn't go through all of your code, I have no clue why you're using two seperate dictionaries, but you'd probably be able to get rid of the duplicatessecond one by rewriting your program slightly. [dictionary1 is equal to dictionary2]

  • Make use of the string module:

      >>> import string
      >>> string.ascii_lowercase
      'abcdefghijklmnopqrstuvwxyz'
      >>> string.ascii_uppercase
      'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
      >>> string.digits
      '0123456789'
      >>> string.punctuation
      '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
    
  • You really should limit typecastingThere's no need to cast the filename to a minimum, because it confuses others who look at your codestring:

      dicname = 'dict/base.txt'
      # Anyone remotely familiar with Python understands that dicname is str.a `str`
      with open(str(dicname), "wb") as fp:
      # Confusing, because this makes it seem as though itit's gotnot typecasteda beforehand.`str`
    

I haven't time to fully review your code (at least for now), but here's some recommendations:

  • If I'm not mistaken, xrange() starts at 0 if no first argument is given (this is the case with range() in Python 3). So unless you need to start at another value, leave out the first argument and just call xrange(end). The same goes for random.randrange(), by the way.

  • Some of your variable names are bad (non-descriptive). Especially dictionary1 and dictionary2, among others (all_chars2). As I didn't go through all of your code, I have no clue why you're using two seperate dictionaries, but you'd probably be able to get rid of the duplicates by rewriting your program. [dictionary1 is equal to dictionary2]

  • Make use of the string module:

      >>> import string
      >>> string.ascii_lowercase
      'abcdefghijklmnopqrstuvwxyz'
      >>> string.ascii_uppercase
      'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
      >>> string.digits
      '0123456789'
      >>> string.punctuation
      '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
    
  • You really should limit typecasting to a minimum, because it confuses others who look at your code:

      dicname = 'dict/base.txt'
      # Anyone remotely familiar with Python understands that dicname is str.
      with open(str(dicname), "wb") as fp:
      # Confusing, because this makes it seem as though it got typecasted beforehand.
    

I don't have time to review all of your code (at least for now), but here's some recommendations:

  • If I'm not mistaken, xrange starts at 0 if no first argument is given (this is the case with range in Python 3). So unless you need to start at another initial value, leave out the first argument and just call xrange(<upper bound>). The same goes for random.randrange, by the way.

  • Some of your variable names are not descriptive. In particular dictionary1 and dictionary2, and all_chars2. As I didn't go through all of your code, I have no clue why you're using two seperate dictionaries, but you'd probably be able to get rid of the second one by rewriting your program slightly.

  • Make use of the string module:

      >>> import string
      >>> string.ascii_lowercase
      'abcdefghijklmnopqrstuvwxyz'
      >>> string.ascii_uppercase
      'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
      >>> string.digits
      '0123456789'
      >>> string.punctuation
      '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
    
  • There's no need to cast the filename to a string:

      dicname = 'dict/base.txt'
      # Anyone remotely familiar with Python understands that dicname is a `str`
      with open(str(dicname), "wb") as fp:
      # Confusing, because this makes it seem as though it's not a `str`
    
Source Link
Daniel
  • 4.6k
  • 2
  • 18
  • 40

I haven't time to fully review your code (at least for now), but here's some recommendations:

  • If I'm not mistaken, xrange() starts at 0 if no first argument is given (this is the case with range() in Python 3). So unless you need to start at another value, leave out the first argument and just call xrange(end). The same goes for random.randrange(), by the way.

  • Some of your variable names are bad (non-descriptive). Especially dictionary1 and dictionary2, among others (all_chars2). As I didn't go through all of your code, I have no clue why you're using two seperate dictionaries, but you'd probably be able to get rid of the duplicates by rewriting your program. [dictionary1 is equal to dictionary2]

  • Make use of the string module:

      >>> import string
      >>> string.ascii_lowercase
      'abcdefghijklmnopqrstuvwxyz'
      >>> string.ascii_uppercase
      'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
      >>> string.digits
      '0123456789'
      >>> string.punctuation
      '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
    
  • You really should limit typecasting to a minimum, because it confuses others who look at your code:

      dicname = 'dict/base.txt'
      # Anyone remotely familiar with Python understands that dicname is str.
      with open(str(dicname), "wb") as fp:
      # Confusing, because this makes it seem as though it got typecasted beforehand.