What do you want to save?
Add Code snippet
New code examples
-
Python 2021-10-14 22:32:04
higlight words in python
from functools import reduce from itertools import chain text = 'left foot right foot left foot right. Feet in the day, feet at night.' l1 = ['foot','feet'] print(reduce(lambda t, x: t.replace(*x), chain([text.lower()], ((t, colored(t,'white','on_red'))... Add solution -
Python 2021-10-14 01:39:08
python itertools repeat()
# How to use it: # repeat(var, amount) # repeat() is basically like range() but it gives an extra arg for a var from itertools import repeat for x in repeat("Spam? Or Eggs?", 3): print(x) > "Spam? Or Eggs?" > "Spam? O... Add solution -
-
Python 2021-09-21 23:05:02
permutations in python
# 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 2021-09-14 08:44:02
matrix multiplication python without numpy
The Numpythonic approach: (using numpy.dot in order to get the dot product of two matrices) In [1]: import numpy as np In [3]: np.dot([1,0,0,1,0,0], [[0,1],[1,1],[1,0],[1,0],[1,1],[0,1]]) Out[3]: array([1, 1]) The Pythonic approach: The length of your ... Add solution -
Python 2021-09-12 00:29:02
pyhton permutations
# 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