Sometimes, while working with Python list, we can have a problem in which we need to extend a list in a very customized way. We may have to repeat contents of list and while doing that, each time new list must be a multiple of original list. This incremental expansion has applications in many domains. Let’s discuss a way in which this task can be performed.
Method : Using list comprehension
This task can be performed in a brute manner, but having a shorter implementation using list comprehension always is better. In this, we perform task in 2 steps, first we make a helper list to form a multiplication factor list and then cumulate the result using original list.
The original list is : [4, 5, 6] List after extension and multiplication : [4, 5, 6, 12, 15, 18, 36, 45, 54, 108, 135, 162]
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 - Incremental List Extension
- Python | Repeat each element K times in list
- Python - Repeat Alternate Elements in list
- Python | Sort and store files with same extension
- Python | Multiply Integer in Mixed List of string and numbers
- Python | Extension function operating on Arrays
- Python | Opaque Pointers in C extension modules
- C Extension Module using Python
- C API from Extension Module in Python | Set 1
- C API from Extension Module in Python | Set 2
- Python | Passing Filenames to Extension in C
- Python program to find files having a particular extension using RegEx
- How to get file extension in Python?
- Python - Multiply two list
- Python - Multiply Consecutive elements in list
- Python - Multiply all cross list element pairs
- Python | Multiply all numbers in the list (4 different ways)
- Pafy - Getting Extension of Stream
- Python | Pandas Series.str.repeat()
- Python | Pandas Index.repeat()