Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python print combinations of string

test_str = "abc"
res = [test_str[i: j] for i in range(len(test_str)) 
          for j in range(i + 1, len(test_str) + 1)]
print(res)#['a', 'ab', 'abc', 'b', 'bc', 'c']
Comment

python print combinations of string

import itertools
 
if __name__ == '__main__':
 
    nums = list("ABC")
    permutations = list(itertools.permutations(nums))
 
    # Output: ['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA']
    print([''.join(permutation) for permutation in permutations])
Comment

PREVIOUS NEXT
Code Example
Python :: how to log ip addresses in python 
Python :: get max value column pandas 
Python :: python speech recognition module 
Python :: log of number python 
Python :: python stop daemon thread 
Python :: torchviz 
Python :: Dummy or One Hot Encoding code with pandas 
Python :: how to find duplicate numbers in list in python 
Python :: pandas add rows from df to another 
Python :: python virus 
Python :: pandas print full dataframe 
Python :: python range backward 
Python :: from sklearn.externals import joblib instead use..... 
Python :: read only the first line python 
Python :: pandas repeat rows n times 
Python :: django timezone india 
Python :: how to import data from csv to jupyter notebook 
Python :: django is null 
Python :: tenary operator python 
Python :: how to plotting horizontal bar on matplotlib 
Python :: iris dataset python import 
Python :: play music with time in python 
Python :: how to count number of unique values in a column python 
Python :: discord get username slash command 
Python :: python get username windows 
Python :: swapcase 
Python :: pandas get column names with nan 
Python :: key press python 
Python :: run python file in interactive mode 
Python :: plt.suptitle position 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =