(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to shuffle and print a specified list. Sample Solution Python Code: from random import shuffle color = [‘Red’, ‘Green’, ‘White’, ‘Black’, ‘Pink’, ‘Yellow’] shuffle(color) print(color) Sample Output: [‘Yellow’, ‘Pink’, ‘Green’, ‘Red’, ‘Black’, ‘White’] Write a Python program to shuffle …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to print the numbers of a specified list after removing even numbers from it. Sample Solution Python Code: num = [7,8, 120, 25, 44, 20, 27] num = [x for x in num if x%2!=0] print(num) Sample Output: [7, 25, …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python function that takes two lists and returns True if they have at least one common member. Sample Solution Python Code: def common_data(list1, list2): result = False for x in list1: for y in list2: if x == y: result = True …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to find the list of words that are longer than n from a given list of words. Sample Solution Python Code: def long_words(n, str): word_len = [] txt = str.split(” “) for x in txt: if len(x) > n: word_len.append(x) …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to clone or copy a list. Sample Solution Python Code: original_list = [10, 22, 44, 23, 4] new_list = list(original_list) print(original_list) print(new_list) Sample Output: [10, 22, 44, 23, 4] [10, 22, 44, 23, 4] Write a Python program to …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to check a list is empty or not. Sample Solution Python Code: l = [] if not l: print(“List is empty”) Sample Output: List is empty Write a Python program to check a list is empty or not Free …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to remove duplicates from a list. Sample Solution Python Code: a = [10,20,30,20,10,50,60,40,80,50,40] dup_items = set() uniq_items = [] for x in a: if x not in dup_items: uniq_items.append(x) dup_items.add(x) print(dup_items) Sample Output: {40, 10, 80, 50, 20, 60, 30} …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to count the number of strings where the string length is 2 or more and the first and last character are same from a given list of strings. Sample Solution Python Code: def match_words(words): ctr = 0 for word in …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to get the smallest number from a list. Sample Solution Python Code: def smallest_num_in_list( list ): min = list[ 0 ] for a in list: if a < min: min = a return min print(smallest_num_in_list([1, 2, -8, 0])) Sample Output: …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to get the largest number from a list. Sample Solution Python Code: def max_num_in_list( list ): max = list[ 0 ] for a in list: if a > max: max = a return max print(max_num_in_list([1, 2, -8, 0])) Sample Output: …