- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Custom space size padding in Strings List
When it is required to customize the space size padding in a list of strings, an empty list, an iteration and the ‘append’ method is used.
Below is a demonstration of the same
my_list = ["Python", "is", "great"] print("The list is :") print(my_list) lead_size = 3 trail_size = 2 my_result =  for elem in my_list: my_result.append((lead_size * ' ') + elem + (trail_size * ' ')) print("The result is :") print(my_result)
The list is : ['Python', 'is', 'great'] The result is : [' Python ', ' is ', ' great ']
A list is defined and is displayed on the console.
The lead and trail sizes are defined.
An empty list is defined.
The original list is iterated over, and the lead size and trail sizes are multiplied with empty spaces.
This is appended to the result.
This is the output that is displayed on the console.
- Custom list split in Python
- Python – Filter rows without Space Strings
- Python - Convert List to custom overlapping nested list
- Python - Group contiguous strings in List
- Custom Multiplication in list of lists in Python
- Custom sorting in list of tuples in Python
- Python – Custom Lower bound a List
- Concatenating two strings in MySQL with space?
- Find size of a list in Python
- Convert list of strings to list of tuples in Python
- Convert list of tuples to list of strings in Python
- Extract numbers from list of strings in Python
- How to remove empty strings from a list of strings in Python?
- Python - Ways to merge strings into list
- Python program to remove row with custom list element