Assigning elements to list is a common problem and many varieties of it have been discussed in the previous articles. This particular article discusses the insertion of range of elements in the list. Let’s discuss certain ways in which this problem can be solved.
Method #1 : Using
This can be solved using the extend function in which the insertion of range of numbers can be done on the rear end using the range function.
The original list : [3, 5, 6, 8] The list after adding range elements : [3, 5, 6, 8, 0, 1, 2, 3, 4, 5]
Method #2 Using
This problem can also be solved using the * operator and with the advantage of flexibility of addition of elements at any position.
The original list : [3, 5, 6, 8] The list after adding range elements : [3, 5, 0, 1, 2, 3, 4, 5, 6, 8]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Assign multiple variables with list values
- Python | Assign value to unique number in list
- Python | Assign ids to each unique value in a list
- Python - Assign list items to Dictionary
- Python - Assign values to Values List
- Python - Assign K to Non Max-Min elements in Tuple
- Python - Assign pair elements from Tuple Lists
- Python | Pandas dataframe.assign()
- How to assign values to variables in Python and other languages
- Python - Assign values to initialized dictionary keys
- Python - Assign Reversed Values in Dictionary
- Python - Assign Frequency to Tuples
- Python - Assign Alphabet to each element
- Assign Function to a Variable in Python
- Python - Test if elements of list are in Min/Max range from other list
- Python - Test if List contains elements in Range
- Python | Print list elements in circular range
- Python - Extract range of Consecutive Similar elements ranges from string list
- Python - Test for all Even elements in the List for the given Range
- Python | Convert list of string to list of list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.