Created
August 16, 2021 09:36
-
-
Save shinysu/e95a1fe0380e1e787677d958e0f84934 to your computer and use it in GitHub Desktop.
Day 9
Problems using lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
find the minimum value in the given list | |
''' | |
def find_minimum(numbers): | |
minimum = numbers[0] | |
for x in numbers: | |
if x < minimum: | |
minimum = x | |
return minimum | |
numbers = [] | |
n = int(input("Enter the number of elements:")) | |
for i in range(n): | |
num = int(input()) | |
numbers.append(num) | |
minimum = find_minimum(numbers) | |
print(minimum) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_odd_numbers(numbers): | |
odd_list = [] | |
for number in numbers: | |
if number % 2 != 0: | |
odd_list.append(number) | |
return odd_list | |
numbers = [] | |
n = int(input("Enter the number of elements: ")) | |
for i in range(n): | |
value = int(input()) | |
numbers.append(value) | |
odd_list = get_odd_numbers(numbers) | |
print(odd_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
remove duplicate elements from a given list | |
sample input : [1, 2, 1, 3, 2] | |
sample output: [1, 2, 3] | |
''' | |
def remove_duplicates(original): | |
unique = [] | |
for x in original: | |
if x not in unique: | |
unique.append(x) | |
return unique | |
numbers = [] | |
n = int(input("Enter the number of elements:")) | |
for i in range(n): | |
num = int(input()) | |
numbers.append(num) | |
unique = remove_duplicates(numbers) | |
print(unique) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment