Day_4
Q9. allLongestStrings
Given an array of strings, return another array containing all of its longest strings.
1 2 3 4 5 6 7 8 9 10 11 12
| def allLongestStrings(inputArray): maxLen = 0 for word in inputArray: if maxLen < len(word): maxLen = len(word)
maxLenList = list() for word in inputArray: if len(word) == maxLen: maxLenList.append(word)
return maxLenList
|
오늘부턴 코드 짜는 과정도 메모해둘 수 있으면 메모해서 올리자
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
|
inputArray = ["aba", "aa", "ad", "vcd", "aba"] print(inputArray) print(inputArray[0])
maxLen = 0 for word in inputArray: if maxLen < len(word): maxLen = len(word) print(maxLen)
maxLenList = list() for word in inputArray: if len(word) == maxLen: maxLenList.append(word) print(maxLenList)
|