
- 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 - Ways to merge strings into list
While developing an application, there come many scenarios when we need to operate on the string and convert it as some mutable data structure, say list.
Example
# Importing ast library import ast # Initialization of strings str1 ="'Python', 'for', 'fun'" str2 ="'vishesh', 'ved'" str3 ="'Programmer'" # Initialization of list list = [] # Extending into single list for x in (str1, str2, str3): list.extend(ast.literal_eval(x)) # printing output print(list) # using eval # Initialization of strings str1 ="['python, 'for', ''fun']" str2 ="['vishesh', 'ved']" str3 ="['programmer']" out = [str1, str2, str3] out = eval('+'.join(out)) # printing output print(out)
- Related Articles
- Program to merge strings alternately using Python
- Largest Merge of Two Strings in Python
- All ways to divide array of strings into parts in JavaScript
- Program to find largest merge of two strings in Python
- Program to merge two strings in alternating fashion in Python
- Python - Ways to rotate a list
- Merge two sorted arrays into a list using C#
- Python - Ways to flatten a 2D list
- Python - Ways to remove duplicates from list
- Python - Ways to initialize list with alphabets
- Program to sort all elements in a given list and merge them into a string in Python
- Merge a linked list into another linked list at alternate positions in Java
- Python - Ways to convert array of strings to array of floats
- Program to merge two sorted list to form larger sorted list in Python
- Program to get maximum length merge of two given strings in Python

Advertisements