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
import numpy as np | |
students = ["Alice", "Bob", "Carl", "David"] | |
subjects = ["Math", "Physics", "Biology"] | |
# Quiz scores | |
# - Columns -> subjects | |
# - Rows -> students | |
scores = np.array([[10, 8, 5], [6, 9, 8], [9, 9, 8], [7, 5, 9]]) | |
print("\nSubject and name of the student, and the highest score") |
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
from math import sqrt | |
from itertools import count | |
NUMBER_OF_PRIMES = 10 | |
def primes() -> int: | |
"""Primes generator.""" | |
yield 2 | |
for x in count(3, step=2): |
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
print(*zip(*[iter(range(20)] * 2)) | |
# output | |
# (0, 1) (2, 3) (4, 5) (6, 7) (8, 9) (10, 11) (12, 13) (14, 15) (16, 17) (18, 19) |
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
from time import sleep | |
def progress(percent=0, width=50): | |
left = width * percent // 100 | |
right = width - left | |
print('\r[', '#' * left, ' ' * right, ']', | |
f' {percent:.0f}%', | |
sep='', end='', flush=True) | |
for i in range(101): |
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
from itertools import cycle | |
from time import sleep | |
for frame in cycle(r'-\|/'): | |
print('\r', frame, sep='', end='', flush=True) | |
sleep(0.2) |
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
//Reverse reverses string using strings.Builder. It's about 3 times faster | |
//than the one with using a string | |
// BenchmarkReverse-8 3000000 499 ns/op 56 B/op 6 allocs/op | |
func Reverse(in string) string { | |
var sb strings.Builder | |
runes := []rune(in) | |
for i := len(runes) - 1; 0 <= i; i-- { | |
sb.WriteRune(runes[i]) | |
} | |
return sb.String() |
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
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"os" | |
"strconv" | |
"time" | |
) |
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
package main | |
import ( | |
"fmt" | |
"regexp" | |
"strings" | |
) | |
func preProcess(text string) string { | |
// Find all chars that are not alphabet |
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
/* | |
By default Go interpreter scientific notation to float64. | |
This example shows how to use scientific notation to declare int types. | |
This example also shows how to reuse the same parameter in Printf function. | |
*/ | |
package main | |
import ( | |
"fmt" |
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
/* | |
An example of how to find the difference between two slices. | |
This example uses empty struct (0 bytes) for map values. | |
*/ | |
package main | |
import ( | |
"fmt" | |
) |