- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Equate two list index elements in Python
During data manipulation with Python , we may need to bring two lists together and equate the elements in each of them pair wise. Which means the element at index 0 from list 1 will be equated with element from index 0 of list2 and so on.
With tuple
The tuple function will be leveraged to take elements form each list in sequence and matching them up. We first store the result in a temp string which has the pattern in which the output of matching up of the values form lists will be displayed.
Example
listA = ['day1', 'day2', 'day3'] listB = ['Mon', 'Tue', 'Fri'] # Given lists print("Given list A is : " ,listA) print("Given list B is : " ,listB) # Pairing list elements temp = len(listA) * '% s = %% s, ' res = temp % tuple(listA) % tuple(listB) # printing result print("Paired lists : " , res)
Output
Running the above code gives us the following result −
Given list A is : ['day1', 'day2', 'day3'] Given list B is : ['Mon', 'Tue', 'Fri'] Paired lists : day1 = Mon, day2 = Tue, day3 = Fri,
With join and zip
The zip function can pair up the elements form lists in sequence and the join function will apply the required pattern we need to apply to the pairs.
Example
listA = ['day1', 'day2', 'day3'] listB = ['Mon', 'Tue', 'Fri'] # Given lists print("Given list A is : " ,listA) print("Given list B is : " ,listB) # Pairing list elements res= ', '.join('% s = % s' % i for i in zip(listA, listB)) # printing result print("Paired lists : " , res)
Output
Running the above code gives us the following result −
Given list A is : ['day1', 'day2', 'day3'] Given list B is : ['Mon', 'Tue', 'Fri'] Paired lists : day1 = Mon, day2 = Tue, day3 = Fri
- Related Articles
- Python – Check if elements index are equal for list elements
- Add list elements with a multi-list based on index in Python
- Python – Check if elements in a specific index are equal for list elements
- Python Program that print elements common at specified index of list elements
- Python prorgam to remove duplicate elements index from other list
- Swap Even Index Elements And Odd Index Elements in Python
- Find mismatch item on same index in two list in Python
- Python – Nearest occurrence between two elements in a List
- Python – Index Value repetition in List
- Python - Index Ranks of Elements
- Python – Elements with same index
- Python - Index Directory of Elements
- Program to interleave list elements from two linked lists in Python
- Python Index specific cyclic iteration in list
- Python – Negative index of Element in List

Advertisements