What do you want to save?
Add Code snippet
New code examples
-
Python 2022-03-06 11:10:04
python permutation
# A Python program to print all permutations using library function from itertools import permutations perm = permutations([1, 2, 3]) for i in list(perm): print (i) # (1, 2, 3) # (1, 3, 2) # (2, 1, 3) # (2, 3, 1) # (3, 1, 2) # (3, 2, 1) Add solution -
Python 2022-01-29 12:40:19
python how to unnest a nested list
# Basic syntax: unnested_list = list(chain(*nested_list)) # Where chain comes from the itertools package and is useful for # unnesting any iterables # Example usage: from itertools import chain nested_list = [[1,2], [3,4]] my_unnested_list = list(chain(... Add solution -
-
Python 2021-11-20 13:06:08
compter des valeur consecutives en python
>>> from itertools import groupby >>> def groups(l): ... return [sum(g) for i, g in groupby(l) if i == 1] ... >>> groups([0,1,0,0,0]) [1] >>> groups([0,0,1,1,0]) [2] >>> groups([1,1,0,1,... Add solution -
Python 2021-11-15 22:36:16
write xor decrypt python
def xor_crypt_string(data, key = 'awesomepassword', encode = False, decode = False): from itertools import izip, cycle import base64 if decode: data = base64.decodestring(data) xored = ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(d... Add solution -
Python 2021-10-19 16:25:16
python split dict into chunks
# Since the dictionary is so big, it would be better to keep # all the items involved to be just iterators and generators, like this from itertools import islice def chunks(data, SIZE=10000): it = iter(data) for i in range(0, len(data), SIZE): ... Add solution