Categories:Viewed: 2 - Published at: a few seconds ago

Write a python function to read a CSV file and print its content

def read_csv(filename):
    import csv
    with open(filename, newline='') as f:
        reader = csv.reader(f)
        for row in reader:
            print(row)

Write a python snippet to convert list into indexed tuple

test_list = [4, 5, 8, 9, 10] 
list(zip(range(len(test_list)), test_list))

Write a python function to split word into chars

def split(word): 
    return [char for char in word]

Write a python function to pickle data to a file

def pickle_data(data, pickle_file):
  import pickle
  with open(pickle_file, 'wb') as f:
      pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
  return None

Write a python function to load pickle data from a file

def load_pickle_data(pickle_file):
  import pickle
  with open(pickle_file, 'rb') as f:
      data = pickle.load(f)
  return data

Write a function that adds 2 iterables a and b such that a is even and b is odd

def add_even_odd_list(l1:list,l2:list)-> list:
    return [a+b for a,b in zip(l1,l2) if a%2==0 and b%2!=0]

Write a function that strips every vowel from a string provided

def strip_vowels(input_str:str)->str:

    vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' ]
    return ''.join(list(filter(lambda x: x not in vowels, input_str)))

Write a function that acts like a ReLU function for a 1D array

def relu_list(input_list:list)->list:
    return [(lambda x: x if x >= 0 else 0)(x) for x in input_list]

Write a function that generates Factorial of number

def factorial(n):
    if n == 0 or n ==1:
        return 1
    else:
        return n*factorial(n-1)

Write a function that returns length of the list

def list_length(l):
    return len(l)

Write a function that sorts list of numbers and returns top element

def biggest_no(l:list)->int:
    sorted(l)

Write a function to print a string by repeating it n times

def print_repeatnstring(text:str, n:int)-> str:
    return text*n

Write a function to merge two lists element wise

def merge_lists(l1:list, l2:list):
    return list(zip(l1,l2))

Write a function to merge two lists element wise

def merge_lists(l1:list, l2:list):
    return list(zip(l1,l2))

Write a function to append two lists

def append_lists(l1:list, l2:list)->list:
    return l1.extend(l2)

Write a function to return reverse of a list

def reverse_list(l1:list)->list:
    return l1[::-1]

Write a function to adds two lists element wise

def adds_listelements(l1:list, l2:list):
    return [i+j for i, j in zip(l1,l2)]

Write a function to Subtracts two lists element wise

def sub_listelements(l1:list, l2:list):
    return [i-j for i, j in zip(l1,l2)]

Write a function to adds two lists element wise only if numbers are even

def adds_listevenelements(l1:list, l2:list):
    return [i+j for i, j in zip(l1,l2) if i*j%2 == 0]

Write a function to multiplies two lists element wise only if numbers are odd

def adds_listoddelements(l1:list, l2:list):
    return [i*j for i, j in zip(l1,l2) if i*j%2 == 1]

Write a function that returns list of elements with n power to elements of list

def n_power(l1:list, power:int)->list:
    return [i**power for i in l1]