0
How can i get triplets of a string and print a list with the positions of that triplets?
for example: s="DADGTHDAD" DAD [0, 6] GTH [3]
4 Answers
+ 1
Hey
Firstly you would need to create an empty list
New_list = []
Then split the string into three using the .split and len() functions and then use the new_list.append() function to add it into the list. Consider a for loop to iterate through the split string.
Hope this helps without giving too much away (doing it for you)
Then print(new_list) will print the list out
+ 1
word="abc123def"
n=3
word_list=[word[i:i+n] for i in range(0, len(word), n)]
word_list
['abc', '123', 'def']
+ 1
[i for i,x in enumerate(word_list) if x == "abc"]
#abc Or whatever you're looking for. On output you will get position on a list
0
hi Brt what i should print?