
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python - Increasing alternate element pattern in list
In this we are going to use List Comprehension with enumerate() Python provides compact syntax for deriving one list from another. These expressions are called list comprehensions.List comprehensions are one of the most powerful tools in Python. Python’s list comprehension is an example of the language’s support for functional programming concepts. You can read more about it here "www.tutorialspoint.com/python-list-comprehension" The enumerate() method adds counter to the iterable. You can read more about enumerate here " www.tutorialspoint.com/enumerate-in-python"
Example
# declare list of integers my_list = [1, 2, 3] # printing the value print("Printing my_list list : " + str(my_list)) response = [value for sub in ((i, "*" * j) for j, i in enumerate(my_list, 1)) for value in sub] # print result print("The increasing element pattern IS : " + str(response))
Output
Printing my_list list : [1, 2, 3] The increasing element pattern IS : [1, '*', 2, '**', 3, '***']
- Related Articles
- Increasing alternate element pattern in list in Python
- Alternate element summation in list (Python)
- Alternate range slicing in list (Python)
- Python – Check alternate peak elements in List
- Python – Cross Pattern Pairs in List
- A strictly increasing linked list in Python
- List consisting of all the alternate elements in Python
- Python - List Initialization with alternate 0s and 1s
- Check if list is strictly increasing in Python
- Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple using Python program
- Python program to Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple
- Python Program to Alternate list elements as key-value pairs
- Alternate sorting of Linked list in C++
- Element repetition in list in Python
- Find groups of strictly increasing numbers in a list in Python

Advertisements