- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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
Python Program to Split the array and add the first part to the end
When it is required to split the list, and then add this first part to the end of the list, a simple iteration through the list and list slicing is required.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
Below is a demonstration for the same −
def split_list(my_list, n_val, k_val): for i in range(0, k_val): first_val = my_list for k in range(0, n_val-1): my_list[k] = my_list[k + 1] my_list[n_val-1] = first_val my_list = [34, 42, 56, 78, 9, 0, 23] list_len = len(my_list) pos = 3 print("The list is :") print(my_list) print("The split_list method is being called") split_list(my_list, list_len, pos) for i in range(0, list_len): print(my_list[i])
The list is : [34, 42, 56, 78, 9, 0, 23] The split_list method is being called 78 9 0 23 34 42 56
- A method named ‘split_list’ is defined, that takes a list, and two values as parameters.
- Using simple indexing, the array is split, and the first part of the list is put to the end of the list.
- A list is created, and is displayed on the screen.
- This method is called by passing the list as parameter.
- The output is displayed on the console.
- Java Program to Split the array and add the first part to the end
- C++ Program to Split the array and add the first part to the end?
- C# Program to remove the end part of a string
- Double the first element and move zero to end in C++ Program
- Python Program to move numbers to the end of the string
- Golang Program To Get The First Item From The Array
- C++ Program to get the first item from the array
- Python program to split the even and odd elements into two different lists.
- C# Program to skip elements of an array from the end
- Python program to split and join a string?
- Program to find minimum length of first split of an array with smaller elements than other list in Python
- Golang Program to add a node at the end of a given linked list.
- C# Program to display the first element from an array
- Golang Program to add the first node in a given linked list.
- Add a string to the end of the StringCollection in C#