Python

Python Example – Write a Python program to remove duplicates from a list of lists

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to remove duplicates from a list of lists.   Sample Solution Python Code: import itertools num = [[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]] print(“Original List”, num) num.sort() new_num = list(num for num,_ in itertools.groupby(num)) print(“New List”, new_num) …

Python Example – Write a Python program to find all the values in a list are greater than a specified number

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find all the values in a list are greater than a specified number.   Sample Solution Python Code: list1 = [220, 330, 500] list2 = [12, 17, 21] print(all(x >= 200 for x in list1)) print(all(x >= 25 for x …

Python Example – Write a Python program to find the list in a list of lists whose sum of elements is the highest

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to find the list in a list of lists whose sum of elements is the highest.   Sample Solution Python Code: num = [[1,2,3], [4,5,6], [10,11,12], [7,8,9]] print(max(num, key=sum)) Sample Output: [10, 11, 12]   Write a Python program to find …

Python Example – Write a Python program to access dictionary key’s element by index

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to access dictionary key’s element by index.   Sample Solution Python Code: num = {‘physics’: 80, ‘math’: 90, ‘chemistry’: 86} print(list(num)[0]) Sample Output: physics   Write a Python program to access dictionary key’s element by index Free Machine Learning & Data …

Python Example – Write a Python program to iterate over two lists simultaneously

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to iterate over two lists simultaneously.   Sample Solution Python Code: num = [1, 2, 3] color = [‘red’, ‘white’, ‘black’] for (a,b) in zip(num, color): print(a, b) Sample Output: 1 red 2 white 3 black   Write a Python program …

Python Example – Write a Python program to access dictionary key’s element by index

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to access dictionary key’s element by index.   Sample Solution Python Code: num = {‘physics’: 80, ‘math’: 90, ‘chemistry’: 86} print(list(num)[0]) Sample Output: physics   Write a Python program to access dictionary key’s element by index Free Machine Learning & Data …

Python Example – Write a Python program to iterate over two lists simultaneously

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to iterate over two lists simultaneously.   Sample Solution Python Code: num = [1, 2, 3] color = [‘red’, ‘white’, ‘black’] for (a,b) in zip(num, color): print(a, b) Sample Output: 1 red 2 white 3 black   Write a Python program …

Python Example – Write a Python program to insert a given string at the beginning of all items in a list

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to insert a given string at the beginning of all items in a list.   Sample Solution Python Code: num = [1,2,3,4] print([’emp{0}’.format(i) for i in num]) Sample Output: [’emp1′, ’emp2′, ’emp3′, ’emp4′]   Write a Python program to insert a …

Python Example – Write a Python program to print a list of space-separated elements

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to print a list of space-separated elements.   Sample Solution Python Code: num = [1, 2, 3, 4, 5] print(*num) Sample Output: 1 2 3 4 5   Write a Python program to print a list of space-separated elements Free Machine …