(May-05-2021, 07:20 PM)rexrf Wrote: Im converting the int only once,no you converting it twice
(May-05-2021, 07:02 PM)rexrf Wrote: val = int(sys.argv[1]) if int(sys.argv[1])
Just an example how your code may look
import sys from string import ascii_lowercase def read_file(file="/Users/rexfitzhugh/bin/data/words"): print("opening file..") with open(file) as f: contents = f.read().splitlines() print("contents stored...") return contents def chek(word, ch_map, val): return sum(ch_map.get(ch, 0) for ch in word.lower()) == val if __name__ == '__main__': try: val = int(sys.argv[1]) except (ValueError, IndexError): print("expected a number as an arg") else: ch_map = {v:k for k, v in enumerate(ascii_lowercase, 1)} words = read_file() # instead of reading the whole file in memory you may just iterate over it line by line. matches = [word for word in words if check(word, ch_map, val)]
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs