Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

1 change: 0 additions & 1 deletion README.md.txt

This file was deleted.

51 changes: 51 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os

class EnglishWords():

# Read files and find lenght of lengthy words of inputed words list
def read_files(self, file, filename):
words_list =[]
with open(file, 'r') as data_file:
lines = data_file.readlines()
for line in lines:
data = line.strip()
words_list.append(data)
# Function call to find max length word and its length.
(word, word_length) = self.lengthy_word(words_list)
print(word, word_length)

# Funtion call to find consonant and lenghty consonant.
(consonant_word, consonant_word_len) = self.consonant_word(words_list)
print(consonant_word, consonant_word_len)
return words_list

# Find the lenghty word from the word_list and its lenght.
def lengthy_word(self, words_list):
sorted_words = sorted(words_list, key = len)
return sorted_words[-1], len(sorted_words[-1])

# Find all the consonants from words_list and find lenghty words and its lenght.
def consonant_word(self, words_list):
consonant_list = []
for word in words_list:
VOWELS = ['a','e','i','o','u']
vowels_count=0
for letter in word:
for vow in VOWELS:
if letter == vow:
vowels_count=vowels_count+1
if vowels_count == 0:
consonant_list.append(word)
sorted_consonant_list = sorted(consonant_list, key = len)
return sorted_consonant_list[-1], len(sorted_consonant_list[-1])


if __name__ == "__main__":
# Class object
words = EnglishWords()
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
DATA_DIR = os.path.join(ROOT_DIR, 'words')
for filename in os.listdir(DATA_DIR):
file = os.path.join(DATA_DIR, filename)
words.read_files(file, filename)

Loading