0

I'm trying to make something in python where you put the amount of letters in a word then it searches in a word list for words with that amount of chars.

My code:

import sys

import re

def search(pattern):

    print("Searching...\n\n")

    for i, line in enumerate(open(sys.argv[1])):

        for match in re.finditer(pattern, line):

            print(match.groups())


    print("\n\nFinished.")


while True:

    word = ""

    put = int(input("Amount of Letters in Word: "))

    if put > 25 or put < 3:

        print("Invalid amount of letters.")

    else:

        for n in range(0, put):

            word = word + "."

        word = "^" + word + "$"

        pattern = re.compile(word)

        search(pattern)

I want it to show all words with the amount of letters that you put.

https://i.imgur.com/Kgusvyh.png

List of words:

word
1234
okay
0000
asdfg
asdfh
asdgj

Why does it show ()?

Boobah
  • 1
  • 1
  • 2
  • 1
    you're printing match.groups everytime.. which is probably printing an empty tuple. [this](https://stackoverflow.com/questions/7312020/why-wont-re-groups-give-me-anything-for-my-one-correctly-matched-group) may be why – 0TTT0 Dec 24 '17 at 18:25
  • Nvm, fixed by replacing match.groups() with match.group() – Boobah Dec 24 '17 at 18:47

1 Answers1

0

Fixed by replacing match.groups() with match.group().

Boobah
  • 1
  • 1
  • 2