AmitDiwan has Published 11365 Articles

Python program to check if two lists have at least one common element

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 09:46:25

2K+ Views

To check if two lists have at least one common element, we will loop through list1 and list2 and check for atleast one common element in both the lists. The list is the most versatile datatype available in Python, which can be written as a list of comma-separated values (items) ... Read More

Python program using map function to find row with maximum number of 1's

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 09:03:32

211 Views

In this article, we will learn how to use map function to find row with maximum number of 1's. 2D array is given and the elements of the arrays are 0 and 1. All rows are sorted. We have to find row with maximum number of 1's. Here we use ... Read More

Python program to sort a list according to the second element in the sublist.

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 08:56:19

1K+ Views

In this article, we will sort a list according to the second element in the sublist. Let’s say we have the following list − [['jack', 50], ['antony', 20], ['jones', 87], ['gary', 70], ['tom', 90], ['sam', 110], ['warner', 65]] The output should be the following i.e. sorted according to the ... Read More

Python program to count the elements in a list until an element is a Tuple?

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 08:53:33

417 Views

In this article, we will count the elements in a list until an element is a Tuple. The list is the most versatile datatype available in Python, which can be written as a list of commaseparated values (items) between square brackets. Important thing about a list is that the items ... Read More

Python program to count occurrences of an element in a tuple

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 08:48:53

984 Views

We will see how to count occurrences of an element in a Tuple. A tuple is a sequence of immutable Python objects. Let’s say we have the following input, with the occurrences of 20 to be checked − myTuple = (10, 20, 30, 40, 20, 20, 70, 80) The ... Read More

How we can use Python Tuple within a Tuple?

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 08:23:03

8K+ Views

A Tuple can be used within a Tuple easily. Any item of a Tuple can be a Tuple. Tuples are sequences i.e. a collection of objects which ordered and immutable. To access the Tuple within a Tuple, use the square brackets and the index number of that specific inner Tuple. ... Read More

What is correct syntax to create Python dictionary?

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 08:20:35

3K+ Views

The correct syntax to create a Python Dictionary is storing values in the form of key:value pairs. On the left of colon, we store keys and on the right, values i.e. key:value Dictionary is enclosed by curly bracket and do not allow duplicates. According to the 3.7 Python update, ... Read More

What is correct syntax to create Python lists?

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 08:18:34

3K+ Views

The correct syntax to create a Python List is using the square brackets. Creating a list is as simple as putting different comma-separated values between square brackets. Through this, using Lists you can store multiple items. A list can have integer, string or float elements. With that, we can also ... Read More

How to count elements in a nested Python dictionary?

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 08:15:18

16K+ Views

To count elements in a Nested Dictionary, we can use the Built-in function len(). With that, we can also use a function that recursively calls and calculates the elements in an arbitrary depth nested dictionary. Count Elements in a Dictionary Let us first create a Python Dictionary and count its ... Read More

How to truncate a Python dictionary at a given length?

AmitDiwan

AmitDiwan

Updated on 11-Aug-2022 08:12:24

2K+ Views

To truncate a Python Dictionary at a given length, use the itertools module. This module implements a number of iterator building blocks inspired by constructs from APL, Haskell, and SML. For truncating at a given length, we will use the islice() method of the itertools module. The module standardizes a ... Read More

Advertisements