-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLongestWord.py
More file actions
43 lines (30 loc) · 888 Bytes
/
LongestWord.py
File metadata and controls
43 lines (30 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# GHC Codepath SE101 - Sandbox 4
# BASIC
#!/bin/python3
import math
import os
import random
import re
import sys
# The function is expected to return a STRING.
# The function accepts STRING_ARRAY words as parameter.
# This function will go through an array of strings,
# identify the largest word, and return that word.
def longestWord(words):
max_word = ""
for i in words:
# longest string on basis of len
word = max(i.split(), key = len)
if len(max_word) < len(word):
max_word = word
return max_word
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
words_count = int(input().strip())
words = []
for _ in range(words_count):
words_item = input()
words.append(words_item)
result = longestWord(words)
fptr.write(result + '\n')
fptr.close()