Created
August 4, 2019 02:49
-
-
Save jose-almir/5617c5125ab5d1a01af511a6993e7b19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def splitparts(string_seq, parts): | |
""" | |
Args: | |
string_seq(str): sequências em string, como "ARARA", "VOO", "AVES". | |
parts(int): critério para quebrar a sequência em string | |
Returns: | |
Retorna a lista dividida de acordo com o critério parts, veja | |
exemplos: | |
1) splitparts("ARARA", 2) -> ["AR", "AR", "A"] | |
2) splitparts("Fraseextensa!", 3) -> ['Fra', 'see', 'xte', 'nsa', '!'] | |
Caso o tamanho da sequência em string não for divisível pelo critério | |
de parts, a lista dividida terá aparência similar a do exemplo 2. | |
""" | |
divider = sum(divmod(len(string_seq), parts)) | |
splitparts_list = [] | |
for _ in range(divider): | |
if not string_seq: | |
break | |
splitparts_list.append(string_seq[:parts]) | |
string_seq = string_seq[parts:] | |
return splitparts_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment