- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
- C++ Program to Split the array and add the first part to the end?
- Java 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
- How to display the first part of the file in the Linux system?
- Getting the first part from the Postcode in MySQL
- Move the first row to the end of the JTable in Java Swing
- Add an object to the end of the ArrayList in C#
- Add a string to the end of the StringCollection in C#
- Java Program to get the beginning and end date of the week
- C# Program to skip elements of an array from the end
- Python program to split the even and odd elements into two different lists.
- Add an object to the end of Collection in C#
- C# Program to display the first element from an array
- Golang Program to add the first node in a given linked list.