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]
- Python - Test if List contains elements in Range
- Python | Print list elements in circular range
- Python | Assign ids to each unique value in a list
- Python - Assign K to Non Max-Min elements in Tuple
- Python | Assign value to unique number in list
- Python - Assign list items to Dictionary
- Python | Assign multiple variables with list values
- Python | Merge List with common elements in a List of Lists
- Python | Replace elements in second list with index of same element in first list
- Python | Add list elements with a multi-list based on index
- Python | Sorting list of lists with similar list elements
- Python | Subtract two list elements if element in first list is greater
- range() to a list in Python
- Python - Convert Value list elements to List records
- Python - Check List elements from Dictionary List