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]

28th Dec 2016, 5:36 PM
MIGUEL GARCÍA GÓMEZ
MIGUEL GARCÍA GÓMEZ - avatar
4 Respuestas
+ 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
28th Dec 2016, 7:09 PM
Paul Bartholomew
+ 1
word="abc123def" n=3 word_list=[word[i:i+n] for i in range(0, len(word), n)] word_list ['abc', '123', 'def']
28th Dec 2016, 7:18 PM
Brt
+ 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
28th Dec 2016, 7:42 PM
Brt
0
hi Brt what i should print?
28th Dec 2016, 7:29 PM
MIGUEL GARCÍA GÓMEZ
MIGUEL GARCÍA GÓMEZ - avatar