Skip to main content

All Questions

1 vote
6 answers
165 views

nth substring multiplicity using itertools

I am trying to write a function that returns a string with the nth substring replaced by a new substring. I tried the following: import re from itertools import count text = "...
trophy's user avatar
  • 47
-1 votes
3 answers
71 views

Use the replace method to change multiple characters at a time - Python

I'm trying to replace more than one character in a string with the replace function, but I can't figure out how to achieve this. from itertools import permutations comb = permutations([1, 2, 3, 4, 5, ...
Marius Prakash's user avatar
-2 votes
1 answer
48 views

Combination of words in string in Python without using itertools

Is there any way to get all combination of DYNAMIC string's word without using itertools. ex: s = "James is King" O/P: James is King is James King King is James King James is is King Jame ...
MOHAMMED ASIF KHAN's user avatar
1 vote
1 answer
87 views

How do I replace part of string with various combinations in lookup in Python?

I have the following code replacing every element with it's short form in the lookup: case = ["MY_FIRST_RODEO"] lookup = {'MY': 'M', 'FIRST': 'FRST', 'RODEO' : 'RD', 'FIRST_RODEO': 'FRD', '...
flying_fluid_four's user avatar
0 votes
0 answers
54 views

Create all possible combinations of entries from multiple lists

I have different scalar metrics that I need to take inventory of in a large repository of data. The format of one entry for a metric would look something like this: {a}_{b}_{c}_{d} # Where ...
florence-y's user avatar
1 vote
1 answer
167 views

Using itertools groupby, create groups of elements, if ANY key is same in each element

Given a list of strings, how to group them if any value is similar? inputList = ['w', 'd', 'c', 'm', 'w d', 'm c', 'd w', 'c m', 'o', 'p'] desiredOutput = [['d w', 'd', 'w', 'w d',], ['c', 'c m', 'm',...
Misha Bro's user avatar
0 votes
1 answer
232 views

combine itertools 2 product with specified amount of variables

i am tryin to make a product that has 2 lists with 3 variables each combined into 1 list/product i am trying to combine 3 letters and 3 numbers so i am using string for those this is psuedo code ` ...
blazerlazer's user avatar
1 vote
4 answers
756 views

Print all possible combination of words of length 10 from a list letters with repeating 'A' exactly twice

I have a list of 5 letters ['A', 'B', 'N', 'M','E']. I want to print all the words (word means a sequence of letters, it doesn't have to be a valid English word) of length 10 letters that have exactly ...
Anand_is_goat's user avatar
0 votes
2 answers
87 views

Optimizing finding a string that matches the characters in a substring in any order?

Assuming a list as follows: list_of_strings = ['foo', 'bar', 'soap', 'sseo', 'spaseo', 'oess'] and a sub string to_find = 'seos' I would like to find the string(s) in the list_of_strings that: Have ...
reinhardt's user avatar
  • 2,263
2 votes
2 answers
485 views

python:split a list of strings into multiple lists before a certain value

I have a list as follows, my_list = ['France, the weather is nice', 'the house is beautiful', 'we have a fresh start here','France, the dinner is amazing', 'the lady is lovely', 'France, the house is ...
zara kolagar's user avatar
2 votes
2 answers
1k views

Get all possible string combinations without repetition in python [duplicate]

I want to have all possible combinations of a string without repeating a letter unless it exist more than once. And here some examples to clarify the idea: "421" --> ["421", &...
Hamza Ferchichi's user avatar
2 votes
2 answers
181 views

Permute string by indices

Find all distinct permutations of a string where only certain indices are allowed to be permuted. e.g string_perms('test_world', [2,3]) --> ['test_world', 'tets_world'] I have an answer but it ...
Andy's user avatar
  • 21
2 votes
3 answers
1k views

Replace numbers with letters and offer all permutations

I need to determine all possible letter combinations of a string that has numbers when converting numbers into possible visually similar letters. Using the dictionary: number_appearance = { '1':...
Alison LT's user avatar
  • 405
1 vote
3 answers
83 views

Return lengths of repeating substring

For a given substring, I need to determine all the lengths, in order, of the repeating chains of that substring in a given string. Example: for the substring ATT and a string ATTATTATT GGG ATTATT GGG ...
ichthyophile's user avatar
1 vote
2 answers
816 views

How to generate combination of characters in a string at a particular position?

I have a string list : li = ['a', 'b', 'c', 'd'] Using the following code in Python, I generated all the possible combination of characters for list li and got a result of 256 strings. from itertools ...
raghhav's user avatar
  • 177

15 30 50 per page