본문 바로가기

FOR78

Anagram Detection An anagram is the result of rearranging the letters of a word to produce a new word (see wikipedia). Note: anagrams are case insensitive Complete the function to return true if the two arguments given are anagrams of each other; return false otherwise. Examples "foefet" is an anagram of "toffee" "Buckethead" is an anagram of "DeathCubeK" Solution: def is_anagram(test, original): if len(test) < l.. 2022. 7. 21.
Sum of all the multiples of 3 or 5 Your task is to write function findSum. Upto and including n, this function will return the sum of all multiples of 3 and 5. For example: findSum(5) should return 8 (3 + 5) findSum(10) should return 33 (3 + 5 + 6 + 9 + 10) Solution: def find(n): return sum([i for i in range(1, n+1) if i%3 == 0 or i%5 == 0]) 1. Find a number less than 'n'. 2. Find a number that is divisible by 3 or divisible by 5.. 2022. 7. 20.
Find the capitals Instructions Write a function that takes a single string (word) as argument. The function must return an ordered list containing the indexes of all capital letters in the string. Example Test.assertSimilar( capitals('CodEWaRs'), [0,3,4,6] ); Solution: 1. Find the uppercase character in the string. 2. It returns the index of the corresponding character in an array. def capitals(word): return [i f.. 2022. 5. 9.
Coding Meetup #5 - Higher-Order Functions Series - Prepare the count of languages You will be given an array of objects (associative arrays in PHP, table in COBOL) representing data about developers who have signed up to attend the next coding meetup that you are organising. Your task is to return an object (associative array in PHP, table in COBOL) which includes the count of each coding language represented at the meetup. For example, given the following input array: list1 .. 2022. 5. 8.
Initialize my name Some people just have a first name; some people have first and last names and some people have first, middle and last names. You task is to initialize the middle names (if there is any). Examples 'Jack Ryan' => 'Jack Ryan' 'Lois Mary Lane' => 'Lois M. Lane' 'Dimitri' => 'Dimitri' 'Alice Betty Catherine Davis' => 'Alice B. C. Davis' Solution: 1. If there are 3 or more elements of name, only the f.. 2022. 5. 7.
Even numbers in an array Given an array of numbers, return a new array of length number containing the last even numbers from the original array (in the same order). The original array will be not empty and will contain at least "number" even numbers. For example: ([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) => [4, 6, 8] ([-22, 5, 3, 11, 26, -6, -7, -8, -9, -8, 26], 2) => [-8, 26] ([6, -25, 3, 7, 5, 5, 7, -3, 23], 1) => [6] Solutio.. 2022. 5. 6.