Use the Pillow module for Python to "roll" images horizontally or vertically. When an image is rolled, it is shifted in some direction. The part of the image that would be lost as a result of that shift is added onto the opposite side of the image.
This file contains hidden or 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 nestedFor(m, n): | |
"""add each element of m to each element of n""" | |
result = [] | |
for i in m: | |
for j in n: | |
result.append(i+j) | |
return result |
This file contains hidden or 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
# Note: Regex developed using regex101.com, which generated this code, then was edited further. | |
# See: https://regex101.com/r/Vj3CHI/5 | |
# The regex below is part of the solution for HackerRank challenge: | |
# https://www.hackerrank.com/challenges/validate-a-roman-number | |
# The regex is probably incomplete, but it's good enough to pass HackerRank tests. | |
import re | |
regex = r'^(M{,3}(?=([^M]))){,1}([C]{,1}M{,1}){,1}([C]{,1}D{,3}){,1}([X]{,1}C{,3}){,1}(X{,1}L{,1}){,1}(I{,1}X{,3}){,1}(I{1,3}[VX]{,1}|VI{,3}){,1}$' |
This file contains hidden or 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 numbar(n: int) -> str: | |
""" | |
Make a string of digits for numbering columns in the output. Column | |
numbering begins with zero. If the number of columns require more | |
place values, newlines are used to make multiple rows in the output. | |
E.g., if `n <= 10`, there will be one row of output, but if | |
`10 < n <= 100`, there will be two rows of output, etc. | |
""" | |
rows = len(str(n - 1)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
𝐀 = {'😀': 5} | |
for ℹ︎ in range(20): | |
# print(i, ℹ︎, i == ℹ︎) # NameError: name 'i' is not defined. | |
for _,__ in 𝐀.items(): | |
if __ == ℹ︎: | |
print(_, ℹ︎) | |
print(𝐀) # Prints dictionary in 𝐀 | |
print(A) # Also prints dictionary in 𝐀! | |
print(𝐀 is A) # True |
This file contains hidden or 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
class IndexFormatter: | |
def __init__(self, volumeId: int): | |
self.itemPages = ( | |
ItemPage.objects.filter(volume__id=volumeId) | |
.order_by('item__topic__name', F('page') * 1, 'item__name')) | |
def format(self) -> str: | |
""" | |
Format the index for printing. | |
""" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
By Anmol Tomar on CodeX
Nov 29, 2022
Useful notes about using jq.
- Print all paths to values
jq -c paths
Prints each path as an array and doesn't show values.jq --stream 'select(.[1]|scalars!=null) | "\(.[0]|join(".")): \(.[1]|tojson)"' example.json
Nearly perfect. If each path shown began with.
and array indices were enclosed in square brackets, then each one would be a valid jq query string.
NewerOlder