 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – Substitute prefix part of List
When it is required to substitute prefix part of a list, the ‘len’ method and the ‘:’ operator is used.
Example
Below is a demonstration of the same −
my_list_1 = [15, 44, 82] my_list_2 = [29, 77, 19, 44, 26, 18] print("The first list is : " ) print(my_list_1) print("The second list is : " ) print(my_list_2) print("The first list after sorting is :") my_list_1.sort() print(my_list_1) print("The first list after sorting is :") my_list_2.sort() print(my_list_2) my_result = my_list_1 + my_list_2[len(my_list_1) : ] print("The resultant list is : ") print(my_result)  Output
The first list is : [15, 44, 82] The second list is : [29, 77, 19, 44, 26, 18] The first list after sorting is : [15, 44, 82] The first list after sorting is : [18, 19, 26, 29, 44, 77] The resultant list is : [15, 44, 82, 29, 44, 77]
Explanation
- Two lists are defined and are displayed on the console. 
- They are sorted and displayed on the console. 
- Both the lists are added, wherein in the second list, a specific length of the list is taken. 
- This result is assigned to a variable. 
- This is displayed as the output on the console. 
Advertisements
 