Write a python function that would read the given input file path and print its contents
def read_and_print_file(filepath):
with open(filepath, "r") as infile:
print( infile.read() )
Write a python program that would print the first n positive integers using a for loop
n = 62
for num in range(n):
print(num)
def sort_ascending(list_to_be_sorted):
return sorted(list_to_be_sorted)
def sort_descending(list_to_be_sorted):
return sorted(list_to_be_sorted, reverse=True)
def sum_first_n(n):
return ( n * (n+1) ) // 2
def sum_first_n_recursive(n):
if n == 0:
return 0
return sum_first_n_recursive(n-1) + n
def filter_with_key_value(list_of_dicts, key, value):
return list( filter( lambda x: x.get(key) == value, list_of_dicts ) )
def reverse(seq):
SeqType = type(seq)
emptySeq = SeqType()
if seq == emptySeq:
return emptySeq
restrev = reverse(seq[1:])
first = seq[0:1]
result = restrev + first
return result
def square(x):
return x**2
def selection_sort(list_to_be_sorted):
sorted_list = list_to_be_sorted[:]
for i in range(len(sorted_list)):
new_min = sorted_list[i]
new_min_old_place = i
for j in range(i+1, len(sorted_list)):
if new_min > sorted_list[j]:
new_min = sorted_list[j]
new_min_old_place = j
old_val = sorted_list[i]
sorted_list[i] = new_min
sorted_list[new_min_old_place] = old_val
return sorted_list