As in JavaScript, we can use the ^
symbol for XOR (exclusive or) operations.
print(
1 ^ 2, # 3
5 ^ 1, # 4
10 ^ 2, # 8
1 ^ 1, # 0
You can convert a 1
to its boolean opposite (and vice versa) using int(not bool(n))
. This converts n
to a boolean value using bool()
, uses the not
keyword to get the boolean opposite of this value, and then converts this value to an integer with int()
.
print(
int(not bool(1)), # 0
int(not bool(0)), # 1
)
Basic keys:
AWSTemplateFormatVersion: "2010-09-09" # AWS Template Format Version will always be 2010-09-09 until AWS updates the format version
Description: a sample template # Description: string
Resources: # list of varioues types of resources, including Lambda functions & layers, EC2 instances, S3 buckets, IAM execution roles, etc
SomeResource: # user-given ID (name) for the resource
Type: "AWS::EC2::Instance" # type of the resource. See AWS resource and property types reference in references
Properties: # properties that are unique to the resource type. See AWS resource and property types reference in references for a list of available properties on each resource type
The snippet below implements a ListNode
and a LinkedList
class. The LinkedList
can be constructed using an array of numbers, and although it doesn't allow for modification after creation, this could be set up.
There are a lot of JavaScript linked list examples online that require the linked list to be manually constructed, but this implementation just needs to ingest an array of numbers in order to construct the linked list.
This LinkedList
class exposes head
and tail
properties. It could be set up to be traversed from either end.
class ListNode {
Sometimes you'll need to calculate what's called a triangular number. You'll know you have a triangular number on your hands when you have a number (say 5), and you want to get the sum of all positive integers up to and including the number itself (1 + 2 + 3 + 4 + 5).
As an example, maybe you want to find all repeating as well as singular character sequences in a string.
aaaa