(Python Example for Citizen Data Scientist & Business Analyst) Write a python program to check whether two lists are circularly identical. Sample Solution Python Code: list1 = [10, 10, 0, 0, 10] list2 = [10, 10, 10, 0, 0] list3 = [1, 10, 10, 0, 0] print(‘Compare list1 and list2’) print(‘ ‘.join(map(str, list2)) …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to select an item randomly from a list. Sample Solution Python Code: import random color_list = [‘Red’, ‘Blue’, ‘Green’, ‘White’, ‘Black’] print(random.choice(color_list)) Sample Output: Black Write a Python program to select an item randomly from a list Free Machine …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to append a list to the second list. Sample Solution Python Code: list1 = [1, 2, 3, 0] list2 = [‘Red’, ‘Green’, ‘Black’] final_list = list1 + list2 print(final_list) Sample Output: [1, 2, 3, 0, ‘Red’, ‘Green’, ‘Black’] Write …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to flatten a shallow list. Sample Solution Python Code: import itertools original_list = [[2,4,3],[1,5,6], [9], [7,9,0]] new_merged_list = list(itertools.chain(*original_list)) print(new_merged_list) Sample Output: [2, 4, 3, 1, 5, 6, 9, 7, 9, 0] Write a Python program to flatten a …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to find the index of an item in a specified list. Sample Solution Python Code: num =[10, 30, 4, -6] print(num.index(30)) Sample Output: 1 Write a Python program to find the index of an item in a specified list …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to convert a list of characters into a string. Sample Solution Python Code: s = [‘a’, ‘b’, ‘c’, ‘d’] str1 = ”.join(s) print(str1) Sample Output: abcd Free Machine Learning & Data Science Coding Tutorials in Python & R …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program access the index of a list. Sample Solution Python Code: nums = [5, 15, 35, 8, 98] for num_index, num_val in enumerate(nums): print(num_index, num_val) Sample Output: 0 5 1 15 2 35 3 8 4 98 Write a Python …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to get the difference between the two lists. Sample Solution Python Code: list1 = [1, 3, 5, 7, 9] list2=[1, 2, 4, 6, 7, 8] diff_list1_list2 = list(set(list1) – set(list2)) diff_list2_list1 = list(set(list2) – set(list1)) total_diff = diff_list1_list2 + diff_list2_list1 …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to generate all permutations of a list in Python. In mathematics, the notion of permutation relates to the act of arranging all the members of a set into some sequence or order, or if the set is already ordered, rearranging (reordering) …
(Python Example for Citizen Data Scientist & Business Analyst) Write a Python program to generate and print a list of first and last 5 elements where the values are square of numbers between 1 and 30 (both included). Sample Solution Python Code: def printValues(): l = list() for i in range(1,21): l.append(i**2) print(l[:5]) …