
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python – Cross Pattern Pairs in List
When it is required to display cross pattern pairs in list, a list comprehension and the ‘*’ operator are used.
Below is a demonstration of the same −
Example
my_list_1 = [14, 35, 26] my_list_2 = [36, 24, 12] print("The first list is :") print(my_list_1) print("The second list is :") print(my_list_2) result = [i * j for j in my_list_1 for i in my_list_2] print ("The result is :") print(result)
Output
The first list is : [14, 35, 26] The second list is : [36, 24, 12] The result is : [504, 336, 168, 1260, 840, 420, 936, 624, 312]
Explanation
Two lists are defined and displayed on the console.
A list comprehension is used to iterate over the list, and product of the two lists is calculated.
This result is assigned to a variable.
This is the output that is displayed on the console.
- Related Articles
- Python – Cross Pairing in Tuple List
- Python - Total equal pairs in List
- Python - Increasing alternate element pattern in list
- Increasing alternate element pattern in list in Python
- Python - Split list into all possible tuple pairs
- Python Program to Alternate list elements as key-value pairs
- Find pairs with given product in a sorted Doubly Linked List in Python
- Python program to find sum of absolute difference between all pairs in a list
- Python - Make pair from two list such that elements are not same in pairs
- Phyllotaxis pattern in Python?
- Program to find sum of concatenated pairs of all each element in a list in Python?\n
- Unix filename pattern matching in Python
- Pattern matching in Python with Regex
- Find and Replace Pattern in Python
- How to print pattern in Python?

Advertisements