AmitDiwan has Published 10744 Articles

Python program for most frequent word in Strings List

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:38:16

5K+ Views

When it is required to find the most frequent word in a list of strings, the list is iterated over and the ‘max’ method is used to get the count of the highest string.ExampleBelow is a demonstration of the samefrom collections import defaultdict my_list = ["python is best for coders", ... Read More

Python program to get maximum of each key Dictionary List

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:35:40

237 Views

When it is required to get the maximum of each key in a list of dictionary elements, a simple iteration is used.ExampleBelow is a demonstration of the samemy_list = [{"Hi": 18, "there": 13, "Will": 89}, {"Hi": 53, "there": 190, "Will": 87}] print("The list is : ") ... Read More

Python program to count the pairs of reverse strings

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:33:41

170 Views

When it is required to count the pairs of reverse strings, a simple iteration is used.ExampleBelow is a demonstration of the samemy_list = [{"Python": 8, "is": 1, "fun": 9}, {"Python": 2, "is": 9, "fun": 1}, {"Python": 5, "is": 10, "fun": 7}] print("The list is :") print(my_list) result = ... Read More

Python Pandas - Convert Nested Dictionary to Multiindex Dataframe

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:33:18

1K+ Views

At first, let us create a Nested Dictionary −dictNested = {'Cricket': {'Boards': ['BCCI', 'CA', 'ECB'], 'Country': ['India', 'Australia', 'England']}, 'Football': {'Boards': ['TFA', 'TCSA', 'GFA'], 'Country': ['England', 'Canada', 'Germany'] }}Now, create an Empty Dictionary −new_dict = {}Now, loop to assign values −for outerKey, innerDict in dictNested.items(): ... Read More

Python program to print elements which are multiples of elements given in a list

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:31:21

328 Views

When it is required to print the elements which are multiples of elements given in a list, a list comprehension is used.ExampleBelow is a demonstration of the samemy_list = [45, 67, 89, 90, 10, 98, 10, 12, 23] print("The list is :") print(my_list) my_division_list = [6, 4] print("The ... Read More

Python Program to print strings based on the list of prefix

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:29:27

404 Views

When it is required to print strings based on the list of prefix elements, a list comprehension, the ‘any’ operator and the ‘startswith’ method are used.ExampleBelow is a demonstration of the samemy_list = ["streek", "greet", "meet", "leeks", "mean"] print("The list is : ") print(my_list) prefix_list = ["st", "ge", ... Read More

Python program to remove row with custom list element

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:27:57

162 Views

When it is required to remove row with custom list element, a list comprehension and the ‘any’ operator are used.ExampleBelow is a demonstration of the samemy_list = [[14, 3, 11], [66, 27, 8], [31, 12, 21], [11, 16, 26]] print("The list is :") print(my_list) check_list = [3, 10, ... Read More

Python prorgam to remove duplicate elements index from other list

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:26:14

262 Views

When it is required to remove duplicate elements index from other list, the ‘enumerate’ attribute, the list comprehension and a simple iteration are used.ExampleBelow is a demonstration of the samemy_list_1 = [4, 5, 6, 5, 4, 7, 8, 6] my_list_2 = [1, 7, 6, 4, 7, 9, 10, 11] ... Read More

Python Program to remove a specific digit from every element of the list

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:22:09

536 Views

When it is required to remove specific digit from every element of the list, an iteration and ‘set’ operator and ‘str’ methods are used.ExampleBelow is a demonstration of the samemy_list = [123, 565, 1948, 334, 4598] print("The list is :") print(my_list) key = 3 print("The key is :") ... Read More

Python Pandas – Display all the column names in a DataFrame

AmitDiwan

AmitDiwan

Updated on 16-Sep-2021 08:21:07

974 Views

To display only the column names in a DataFrame, use dataframe.columns.Import the required library with an alias −import pandas as pd;Following is the DataFrame −dataFrame = pd.DataFrame(    {       "Car": ['BMW', 'Audi', 'BMW', 'Lexus', 'Tesla', 'Lexus', 'Mustang'], "Place": ['Delhi', 'Bangalore', 'Hyderabad', 'Chandigarh', 'Pune', 'Mumbai', 'Jaipur'], "Units": [100, ... Read More

Advertisements