View reverse_string.py
This file contains 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
# 1. Slicing | |
def reverse_slicing(s): | |
return s[::-1] | |
# 2. Looping with for and while loops | |
# 2.1 for loop | |
def reverse_for_loop(s): | |
s1 = "" | |
for c in s: | |
s1 = c + s1 |
View pathlib_vs_os.py
This file contains 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
from pathlib import Path | |
import os | |
pathlib_cwd = Path.cwd() | |
os_cwd = os.getcwd() | |
print(type(pathlib_cwd)) | |
print(type(os_cwd)) |
View removeTargets.py
This file contains 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
numbers = [1, 4, 4, 26, 4, 4, 8, 0, 4] | |
target = 4 | |
i = 0 | |
while i < len(numbers): | |
if numbers[i] == target: | |
numbers.pop(i) | |
i -= 1 | |
i += 1 | |
View example.py
This file contains 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
if "Alice" not in queue: print("Alice is not in the queue") |
View example.py
This file contains 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
# How would you count the numbers in this list in as few lines of code as possible? | |
numbers = [1, 2, 3, 4, 5] | |
# 1. Charlie sums the numbers up using a for loop: | |
total = 0 | |
for number in numbers: | |
total += number | |
# 2. Bob sums the numbers up using the reduce function: | |
from functools import reduce |
View example.swift
This file contains 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 Fruit { var name = "Banana" } | |
let fruit1 = Fruit() | |
let fruit2 = fruit1 | |
print(fruit1 === fruit2) |
View example.swift
This file contains 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
let a = 1 | |
let b = 1 | |
print(a == b) |
View example.swift
This file contains 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
struct Fruit { | |
let name: String | |
let color: String | |
} | |
var banana = Fruit(name: "Banana", color: "Yellow") | |
print(banana.name, banana.color) |
View example.swift
This file contains 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
struct Fruit { | |
let name: String | |
let color: String | |
init(name: String, color: String) { | |
self.name = name | |
self.color = color | |
} | |
} |
View example.swift
This file contains 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
var a = 1 | |
var b = 2 | |
(a, b) = (b, a) | |
print(a, b) |
NewerOlder