Skip to content

Final-PythonFoundationHomework/high_order_function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Problems

min_task_1_1

Find the smallest number in the list.

Example:

Input: [3, 1, 4, 2]
Output: 1

min_task_1_2

Find the shortest word.

Example:

Input: ["apple", "banana", "kiwi", "pear"]
Output: "kiwi"

min_task_1_3

Find the string with the smallest number of vowels.

Example:

Input: ["book", "sky", "quiet", "data"]
Output: "sky"

Hint: Use key=lambda word: count_vowels(word)

min_task_1_4

Find the dictionary with the smallest value.

Example:

Input: [{'a': 5}, {'a': 3}, {'a': 7}]
Output: {'a': 3}

Hint: key=lambda d: d['a']

min_task_1_5

Find the tuple with the smallest second element.

Example:

Input: [(1, 3), (2, 2), (3, 1)]
Output: (3, 1)

max_task_2_1

Find the largest number in the list.

Example:

Input: [7, 4, 9, 1]
Output: 9

max_task_2_2

Find the longest word.

Example:

Input: ["pen", "notebook", "eraser"]
Output: "notebook"

max_task_2_3

Find the name with the highest number of letters.

Example:

Input: ["Ann", "Robert", "Charlotte", "Mike"]
Output: "Charlotte"

max_task_2_4

Find the word with the most vowels.

Example:

Input: ["tree", "education", "sky", "road"]
Output: "education"

max_task_2_5

Find the person with the highest age.

Example:

Input: [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 45}, {"name": "Tom", "age": 28}]
Output: {"name": "Bob", "age": 45}

map_task_3_1

Add 10 to each number.

Example:

Input: [1, 2, 3]
Output: [11, 12, 13]

map_task_3_2

Convert all words to uppercase.

Example:

Input: ["cat", "dog", "fish"]
Output: ["CAT", "DOG", "FISH"]

map_task_3_3

Get the lengths of each word.

Example:

Input: ["hi", "hello", "bye"]
Output: [2, 5, 3]

map_task_3_4

Square each number.

Example:

Input: [1, 4, 5]
Output: [1, 16, 25]

map_task_3_5

Extract names from a list of dictionaries.

Example:

Input: [{"name": "Alice"}, {"name": "Bob"}, {"name": "Carol"}]
Output: ["Alice", "Bob", "Carol"]

filter_task_4_1

Filter out even numbers.

Example:

Input: [1, 2, 3, 4, 5]
Output: [1, 3, 5]

filter_task_4_2

Keep words longer than 4 letters.

Example:

Input: ["hi", "hello", "world", "cat"]
Output: ["hello", "world"]

filter_task_4_3

Keep numbers greater than 10.

Example:

Input: [5, 11, 20, 7, 10]
Output: [11, 20]

filter_task_4_4

Filter names that start with "A".

Example:

Input: ["Alice", "Bob", "Anna", "Charlie"]
Output: ["Alice", "Anna"]

filter_task_4_5

Keep words that contain the letter "e".

Example:

Input: ["dog", "elephant", "cat", "eagle"]
Output: ["elephant", "eagle"]

lambda_task_5_1

Use lambda to square a number.

Example:

Input: lambda x: x**2, input 5
Output: 25

lambda_task_5_2

Use lambda to return the last character of a string.

Example:

Input: lambda s: s[-1], input "apple"
Output: "e"

lambda_task_5_3

Sort a list of strings by their length using lambda.

Example:

Input: ["apple", "kiwi", "banana"]
Output: ["kiwi", "apple", "banana"]

lambda_task_5_4

Sort a list of tuples by the second value using lambda.

Example:

Input: [(1, 3), (2, 1), (3, 2)]
Output: [(2, 1), (3, 2), (1, 3)]

lambda_task_5_5

Use lambda to check if a number is even.

Example:

Input: lambda x: x % 2 == 0, input 4
Output: True

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages