
- 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 – Incremental Slice concatenation in String list
When it is required to display incremental slice concatenation in string list, a simple iteration and list slicing is used.
Below is a demonstration of the same −
Example
my_list = ['pyt', 'is', 'all', 'fun'] print("The list is :") print(my_list) my_result = '' for index in range(len(my_list)): my_result += my_list[index][:index + 1] print("The result is :") print(my_result)
Output
The list is : ['pyt', 'is', 'all', 'fun'] The result is : pisallfun
Explanation
A list is defined and displayed on the console.
An empty string is created.
The list is iterated over, and the element is concatenated with the consecutive element.
This result is assigned to a variable.
This is the output that is displayed on the console.
- Related Articles
- String Concatenation by + (string concatenation) operator.
- Concatenation of two String Tuples in Python
- How does concatenation operator work on list in Python?
- String Concatenation in Java
- What is the most efficient string concatenation method in python?
- N element incremental tuples in Python
- How to do string concatenation without '+' operator in Python?
- Avoid Unexpected string concatenation in JavaScript?
- Java program for String Concatenation.
- String Concatenation by concat() method.
- Vertical Concatenation in Matrix in Python
- Convert string enclosed list to list in Python
- C/C++ Macro for string concatenation
- How to perform string aggregation/concatenation in Oracle?
- Return element-wise string multiple concatenation in Numpy

Advertisements