Sometimes, while working with String lists, we can have a problem in which we need to perform all possible concatenations of all the strings that occur in list. This kind of problem can occur in domains such as day-day programming and school programming. Let’s discuss a way in which this task can be performed.
Input : test_list = [‘Gfg’, ‘Best’]
Output : [‘Gfg’, ‘Best’, ‘GfgBest’, ‘BestGfg’]
Input : test_list = [‘Gfg’]
Output : [‘Gfg’]
Method : Using
permutations() + join() + loop
The combination of above functions can be used to solve this problem. In this, we perform the task of concatenation using join() and all possible combination extraction using permutations().
The original list : [‘Gfg’, ‘is’, ‘Best’]
All Sring combinations : [‘Gfg’, ‘is’, ‘Best’, ‘Gfgis’, ‘GfgBest’, ‘isGfg’, ‘isBest’, ‘BestGfg’, ‘Bestis’, ‘GfgisBest’, ‘GfgBestis’, ‘isGfgBest’, ‘isBestGfg’, ‘BestGfgis’, ‘BestisGfg’]
- Python | Convert List of String List to String List
- Python | Convert list of string to list of list
- Python - All possible pairs in List
- Python - All possible space joins in String
- Python | Convert list of tuples to list of list
- Python | Remove all values from a list present in other list
- Program to generate all possible valid IP addresses from given string
- Python | Convert a string representation of list into list
- Python | Convert list of string into sorted list of integer
- Python | Convert list of numerical string to list of Integers
- Python | Convert string enclosed list to list
- Python | Convert mixed data types tuple list to string list
- Python | Convert string List to Nested Character List
- Python Program to convert List of Integer to List of String
- Python - Convert String List to Key-Value List dictionary
- Python - Filter the List of String whose index in second List contaons the given Substring
- Python | Find all close matches of input string from a list
- Python | Insert the string at the beginning of all items in a list
- Python | Reverse All Strings in String List
- Python | Largest number possible from list of given numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.