@@ -914,6 +914,9 @@ msgid ""
914
914
"each. When the iterable is exhausted, return elements from the saved copy. "
915
915
"Repeats indefinitely. Roughly equivalent to::"
916
916
msgstr ""
917
+ "Crie um iterador que devolve elementos do *iterable* assim como salva uma "
918
+ "cópia de cada um. Quando o iterável é esgotado, devolve elementos da cópia "
919
+ "salva. Repete indefinidamente. Aproximadamente equivalente a::"
917
920
918
921
#: ../../library/itertools.rst:350
919
922
msgid ""
@@ -929,19 +932,34 @@ msgid ""
929
932
" for element in saved:\n"
930
933
" yield element"
931
934
msgstr ""
935
+ "def cycle(iterable):\n"
936
+ " # cycle('ABCD') → A B C D A B C D A B C D ...\n"
937
+ "\n"
938
+ " saved = []\n"
939
+ " for element in iterable:\n"
940
+ " yield element\n"
941
+ " saved.append(element)\n"
942
+ "\n"
943
+ " while saved:\n"
944
+ " for element in saved:\n"
945
+ " yield element"
932
946
933
947
#: ../../library/itertools.rst:362
934
948
msgid ""
935
949
"This itertool may require significant auxiliary storage (depending on the "
936
950
"length of the iterable)."
937
951
msgstr ""
952
+ "Esta itertool pode exigir armazenamento auxiliar significativo (dependendo "
953
+ "do comprimento do iterável)."
938
954
939
955
#: ../../library/itertools.rst:368
940
956
msgid ""
941
957
"Make an iterator that drops elements from the *iterable* while the "
942
958
"*predicate* is true and afterwards returns every element. Roughly "
943
959
"equivalent to::"
944
960
msgstr ""
961
+ "Cria um iterador que remove elementos do *iterable* enquanto o *predicate* "
962
+ "for verdadeiro e, em seguida, retorna todos os elementos. Equivalente a:"
945
963
946
964
#: ../../library/itertools.rst:372
947
965
msgid ""
@@ -957,19 +975,35 @@ msgid ""
957
975
" for x in iterator:\n"
958
976
" yield x"
959
977
msgstr ""
978
+ "def dropwhile(predicate, iterable):\n"
979
+ " # dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 8\n"
980
+ "\n"
981
+ " iterator = iter(iterable)\n"
982
+ " for x in iterator:\n"
983
+ " if not predicate(x):\n"
984
+ " yield x\n"
985
+ " break\n"
986
+ "\n"
987
+ " for x in iterator:\n"
988
+ " yield x"
960
989
961
990
#: ../../library/itertools.rst:384
962
991
msgid ""
963
992
"Note this does not produce *any* output until the predicate first becomes "
964
993
"false, so this itertool may have a lengthy start-up time."
965
994
msgstr ""
995
+ "Observe que isso não produz *nenhuma* saída até que o predicado se torne "
996
+ "falso, portanto, esta itertool pode ter um longo tempo de inicialização."
966
997
967
998
#: ../../library/itertools.rst:390
968
999
msgid ""
969
1000
"Make an iterator that filters elements from the *iterable* returning only "
970
1001
"those for which the *predicate* returns a false value. If *predicate* is "
971
1002
"``None``, returns the items that are false. Roughly equivalent to::"
972
1003
msgstr ""
1004
+ "Cria um iterador que filtre elementos do *iterable*, retornando apenas "
1005
+ "aqueles para os quais o *predicate* retorna um valor falso. Se o *predicate* "
1006
+ "for ``None``, retorna os itens que são falsos. Equivalente aproximadamente a:"
973
1007
974
1008
#: ../../library/itertools.rst:395
975
1009
msgid ""
@@ -983,6 +1017,15 @@ msgid ""
983
1017
" if not predicate(x):\n"
984
1018
" yield x"
985
1019
msgstr ""
1020
+ "def filterfalse(predicate, iterable):\n"
1021
+ " # filterfalse(lambda x: x<5, [1,4,6,3,8]) → 6 8\n"
1022
+ "\n"
1023
+ " if predicate is None:\n"
1024
+ " predicate = bool\n"
1025
+ "\n"
1026
+ " for x in iterable:\n"
1027
+ " if not predicate(x):\n"
1028
+ " yield x"
986
1029
987
1030
#: ../../library/itertools.rst:408
988
1031
msgid ""
@@ -992,6 +1035,11 @@ msgid ""
992
1035
"returns the element unchanged. Generally, the iterable needs to already be "
993
1036
"sorted on the same key function."
994
1037
msgstr ""
1038
+ "Cria um iterador que retorna chaves e grupos consecutivos do *iterable*. A "
1039
+ "*key* é uma função que calcula um valor-chave para cada elemento. Se não for "
1040
+ "especificado ou for ``None``, *key* assume como padrão uma função de "
1041
+ "identidade e retorna o elemento inalterado. Geralmente, o iterável precisa "
1042
+ "já estar ordenado na mesma função chave."
995
1043
996
1044
#: ../../library/itertools.rst:414
997
1045
msgid ""
@@ -1001,6 +1049,11 @@ msgid ""
1001
1049
"the same key function). That behavior differs from SQL's GROUP BY which "
1002
1050
"aggregates common elements regardless of their input order."
1003
1051
msgstr ""
1052
+ "O funcionamento de :func:`groupby` é semelhante ao filtro ``uniq`` no Unix. "
1053
+ "Ele gera uma quebra ou um novo grupo sempre que o valor da função da tecla "
1054
+ "muda (razão pela qual geralmente é necessário ordenar os dados usando a "
1055
+ "mesma função da tecla). Esse comportamento difere do GROUP BY do SQL, que "
1056
+ "agrega elementos comuns independentemente da ordem de entrada."
1004
1057
1005
1058
#: ../../library/itertools.rst:420
1006
1059
msgid ""
@@ -1009,6 +1062,11 @@ msgid ""
1009
1062
"`groupby` object is advanced, the previous group is no longer visible. So, "
1010
1063
"if that data is needed later, it should be stored as a list::"
1011
1064
msgstr ""
1065
+ "O grupo retornado é, ele próprio, um iterador que compartilha o iterável "
1066
+ "subjacente com :func:`groupby`. Como a origem é compartilhada, quando o "
1067
+ "objeto :func:`groupby` avança, o grupo anterior não fica mais visível. "
1068
+ "Portanto, se esses dados forem necessários posteriormente, eles devem ser "
1069
+ "armazenados como uma lista:"
1012
1070
1013
1071
#: ../../library/itertools.rst:425
1014
1072
msgid ""
@@ -1019,6 +1077,13 @@ msgid ""
1019
1077
" groups.append(list(g)) # Store group iterator as a list\n"
1020
1078
" uniquekeys.append(k)"
1021
1079
msgstr ""
1080
+ "groups = []\n"
1081
+ "uniquekeys = []\n"
1082
+ "data = sorted(data, key=keyfunc)\n"
1083
+ "for k, g in groupby(data, keyfunc):\n"
1084
+ " groups.append(list(g)) # armazena um iterador de grupo como uma "
1085
+ "lista\n"
1086
+ " uniquekeys.append(k)"
1022
1087
1023
1088
#: ../../library/itertools.rst:432
1024
1089
msgid ":func:`groupby` is roughly equivalent to::"
@@ -1058,32 +1123,73 @@ msgid ""
1058
1123
" for _ in curr_group:\n"
1059
1124
" pass"
1060
1125
msgstr ""
1126
+ "def groupby(iterable, key=None):\n"
1127
+ " # [k for k, g in groupby('AAAABBBCCDAABBB')] → A B C D A B\n"
1128
+ " # [list(g) for k, g in groupby('AAAABBBCCD')] → AAAA BBB CC D\n"
1129
+ "\n"
1130
+ " keyfunc = (lambda x: x) if key is None else key\n"
1131
+ " iterator = iter(iterable)\n"
1132
+ " exhausted = False\n"
1133
+ "\n"
1134
+ " def _grouper(target_key):\n"
1135
+ " nonlocal curr_value, curr_key, exhausted\n"
1136
+ " yield curr_value\n"
1137
+ " for curr_value in iterator:\n"
1138
+ " curr_key = keyfunc(curr_value)\n"
1139
+ " if curr_key != target_key:\n"
1140
+ " return\n"
1141
+ " yield curr_value\n"
1142
+ " exhausted = True\n"
1143
+ "\n"
1144
+ " try:\n"
1145
+ " curr_value = next(iterator)\n"
1146
+ " except StopIteration:\n"
1147
+ " return\n"
1148
+ " curr_key = keyfunc(curr_value)\n"
1149
+ "\n"
1150
+ " while not exhausted:\n"
1151
+ " target_key = curr_key\n"
1152
+ " curr_group = _grouper(target_key)\n"
1153
+ " yield curr_key, curr_group\n"
1154
+ " if curr_key == target_key:\n"
1155
+ " for _ in curr_group:\n"
1156
+ " pass"
1061
1157
1062
1158
#: ../../library/itertools.rst:470
1063
1159
msgid ""
1064
1160
"Make an iterator that returns selected elements from the iterable. Works "
1065
1161
"like sequence slicing but does not support negative values for *start*, "
1066
1162
"*stop*, or *step*."
1067
1163
msgstr ""
1164
+ "Cria um iterador que retorna os elementos selecionados do iterável. Funciona "
1165
+ "como o fatiamento de sequência, mas não oferece suporte a valores negativos "
1166
+ "para *start*, *stop* ou *step*."
1068
1167
1069
1168
#: ../../library/itertools.rst:474
1070
1169
msgid ""
1071
1170
"If *start* is zero or ``None``, iteration starts at zero. Otherwise, "
1072
1171
"elements from the iterable are skipped until *start* is reached."
1073
1172
msgstr ""
1173
+ "Se *start* for zero ou ``None``, a iteração começa em zero. Caso contrário, "
1174
+ "os elementos do iterável são pulados até que *start* seja alcançado."
1074
1175
1075
1176
#: ../../library/itertools.rst:477
1076
1177
msgid ""
1077
1178
"If *stop* is ``None``, iteration continues until the input is exhausted, if "
1078
1179
"at all. Otherwise, it stops at the specified position."
1079
1180
msgstr ""
1181
+ "Se *stop* for ``None``, a iteração continua até que a entrada se esgote, se "
1182
+ "for o caso. Caso contrário, ela para na posição especificada."
1080
1183
1081
1184
#: ../../library/itertools.rst:480
1082
1185
msgid ""
1083
1186
"If *step* is ``None``, the step defaults to one. Elements are returned "
1084
1187
"consecutively unless *step* is set higher than one which results in items "
1085
1188
"being skipped."
1086
1189
msgstr ""
1190
+ "Se *step* for ``None``, o padrão do passo é 1. Os elementos são retornados "
1191
+ "consecutivamente, a menos que *step* seja definido como maior que um, o que "
1192
+ "resulta na omissão de itens."
1087
1193
1088
1194
#: ../../library/itertools.rst:486
1089
1195
msgid ""
@@ -1107,12 +1213,34 @@ msgid ""
1107
1213
" yield element\n"
1108
1214
" next_i += step"
1109
1215
msgstr ""
1216
+ "def islice(iterable, *args):\n"
1217
+ " # islice('ABCDEFG', 2) → A B\n"
1218
+ " # islice('ABCDEFG', 2, 4) → C D\n"
1219
+ " # islice('ABCDEFG', 2, None) → C D E F G\n"
1220
+ " # islice('ABCDEFG', 0, None, 2) → A C E G\n"
1221
+ "\n"
1222
+ " s = slice(*args)\n"
1223
+ " start = 0 if s.start is None else s.start\n"
1224
+ " stop = s.stop\n"
1225
+ " step = 1 if s.step is None else s.step\n"
1226
+ " if start < 0 or (stop is not None and stop < 0) or step <= 0:\n"
1227
+ " raise ValueError\n"
1228
+ "\n"
1229
+ " indices = count() if stop is None else range(max(start, stop))\n"
1230
+ " next_i = start\n"
1231
+ " for i, element in zip(indices, iterable):\n"
1232
+ " if i == next_i:\n"
1233
+ " yield element\n"
1234
+ " next_i += step"
1110
1235
1111
1236
#: ../../library/itertools.rst:506
1112
1237
msgid ""
1113
1238
"If the input is an iterator, then fully consuming the *islice* advances the "
1114
1239
"input iterator by ``max(start, stop)`` steps regardless of the *step* value."
1115
1240
msgstr ""
1241
+ "Se a entrada for um iterador, o consumo total do *islice* avança o iterador "
1242
+ "de entrada em ``max(start, stop)`` passos, independentemente do valor do "
1243
+ "*step*."
1116
1244
1117
1245
#: ../../library/itertools.rst:513
1118
1246
msgid "Return successive overlapping pairs taken from the input *iterable*."