Skip to content

Commit abe451f

Browse files
author
abregman
committed
Merge branch 'master' of github.com:bregman-arie/devops-exercises into devel
2 parents 3bbdbaf + 023cf57 commit abe451f

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

.github/workflows/ci_workflow.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on:
4+
# Triggers the workflow on pull request events for the main and devel branch
5+
pull_request:
6+
branches: [ main, devel ]
7+
8+
# Allows running this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
jobs:
12+
# Contains a single job called "ci"
13+
ci:
14+
runs-on: ubuntu-latest
15+
steps:
16+
# Checks out repository under $GITHUB_WORKSPACE, so job can access it
17+
- uses: actions/checkout@v2
18+
- name: Install flake8
19+
run: sudo apt install flake8
20+
- name: Give executable permissions to the script
21+
run: chmod a+x scripts/run_ci.sh
22+
- name: Run the ci script in scripts folder
23+
run: sh scripts/run_ci.sh
24+
shell: bash

README.md

+96-1
Original file line numberDiff line numberDiff line change
@@ -3031,8 +3031,38 @@ You can then assign a function to a variables like this `x = my_function` or you
30313031
<details>
30323032
<summary>Write a function to determine if a number is a Palindrome</summary><br><b>
30333033

3034+
- Code:
3035+
3036+
```
3037+
from typing import Union
3038+
3039+
def isNumberPalindrome(number: Union[int, str]) -> bool:
3040+
if isinstance(number, int):
3041+
number = str(number)
3042+
return number == number[::-1]
3043+
3044+
print(isNumberPalindrome("12321"))
3045+
```
3046+
3047+
- Using Python3.10 that accepts using bitwise operator '|'.
3048+
3049+
```
3050+
def isNumberPalindrome(number: int | str) -> bool:
3051+
if isinstance(number, int):
3052+
number = str(number)
3053+
return number == number[::-1]
3054+
3055+
print(isNumberPalindrome("12321"))
30343056
```
3057+
3058+
Note: Using slicing to reverse a list could be slower than other options like `reversed` that return an iterator.
3059+
3060+
- Result:
3061+
30353062
```
3063+
True
3064+
```
3065+
30363066
</b></details>
30373067

30383068
#### Python - OOP
@@ -3239,6 +3269,28 @@ False
32393269

32403270
<details>
32413271
<summary>What is the __call__ method?</summary><br><b>
3272+
3273+
It is used to emulate callable objects. It allows a class instance to be called as a function.
3274+
3275+
- Example code:
3276+
3277+
```
3278+
class Foo:
3279+
def __init__(self: object) -> None:
3280+
pass
3281+
def __call__(self: object) -> None:
3282+
print("Called!")
3283+
3284+
f = Foo()
3285+
f()
3286+
```
3287+
3288+
- Result:
3289+
3290+
```
3291+
Called!
3292+
```
3293+
32423294
</b></details>
32433295

32443296
<details>
@@ -3425,6 +3477,24 @@ some_list[:3]
34253477

34263478
<details>
34273479
<summary>How to insert an item to the beginning of a list? What about two items?</summary><br><b>
3480+
3481+
- One item:
3482+
3483+
```
3484+
numbers = [1, 2, 3, 4, 5]
3485+
numbers.insert(0, 0)
3486+
print(numbers)
3487+
```
3488+
3489+
- Multiple items or list:
3490+
3491+
```
3492+
numbers_1 = [2, 3, 4, 5]
3493+
numbers_2 = [0, 1]
3494+
numbers_1 = numbers_2 + numbers_1
3495+
print(numbers_1)
3496+
```
3497+
34283498
</b></details>
34293499

34303500
<details>
@@ -3632,6 +3702,31 @@ list(zip(nums, letters))
36323702

36333703
<details>
36343704
<summary>What is List Comprehension? Is it better than a typical loop? Why? Can you demonstrate how to use it?</summary><br><b>
3705+
3706+
From [Docs](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions): "List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition.".
3707+
3708+
It's better because they're compact, faster and have better readability.
3709+
3710+
- For loop:
3711+
3712+
```
3713+
number_lists = [[1, 7, 3, 1], [13, 93, 23, 12], [123, 423, 456, 653, 124]]
3714+
odd_numbers = []
3715+
for number_list in number_lists:
3716+
for number in number_list:
3717+
if number % 2 == 0:
3718+
odd_numbers.append(number)
3719+
print(odd_numbers)
3720+
```
3721+
3722+
- List comprehesion:
3723+
3724+
```
3725+
number_lists = [[1, 7, 3, 1], [13, 93, 23, 12], [123, 423, 456, 653, 124]]
3726+
odd_numbers = [number for number_list in number_lists for number in number_list if number % 2 == 0]
3727+
print(odd_numbers)
3728+
```
3729+
36353730
</b></details>
36363731

36373732
<details>
@@ -7339,7 +7434,7 @@ Not only this will tell you what is expected from you, it will also provide big
73397434
<details>
73407435
<summary>What does it mean when a database is ACID compliant?</summary><br>
73417436

7342-
ACID stands for Atomicity, Consistency, Isolation, Durability. In order to be ACID compliant, the database much meet each of the four criteria
7437+
ACID stands for Atomicity, Consistency, Isolation, Durability. In order to be ACID compliant, the database must meet each of the four criteria
73437438

73447439
**Atomicity** - When a change occurs to the database, it should either succeed or fail as a whole.
73457440

0 commit comments

Comments
 (0)