Skip to content

Instantly share code, notes, and snippets.

@shinysu
Created September 10, 2020 16:32
Show Gist options
  • Select an option

  • Save shinysu/41d129d96895433de552a0d157710604 to your computer and use it in GitHub Desktop.

Select an option

Save shinysu/41d129d96895433de552a0d157710604 to your computer and use it in GitHub Desktop.
day7 examples
'''
check if an element is present in the list
you can use 'in' operator to check if the element is present and 'not in' operator to check if the element is not present
'''
cart = ['ice cream', 'chocolates', 'bread', 'jam', 'butter']
item = input("Enter the element you want to search: ")
if item in cart:
print("yes, the element is present")
else:
print("No, the element is not present")
'''
iterate over a list and print all the elements in the list
'''
cart = ['ice cream', 'chocolates', 'bread', 'jam', 'butter']
for x in cart:
print(x)
'''
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)
'''
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