Skip to content

Commit 51caca8

Browse files
author
Arie Bregman
authored
* Add a couple of exercises Also fixed the link for kubernetes exercises. * Fix kubernetes images Also fixed the link to containers exercises. * Move Python exercises to a separate repository This is the first part in moving Python exercises into their own repository.
1 parent 696eb27 commit 51caca8

File tree

1 file changed

+1
-300
lines changed

1 file changed

+1
-300
lines changed

README.md

Lines changed: 1 addition & 300 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</tr>
3131
<tr>
3232
<td align="center"><a href="exercises/software_development/README.md"><img src="images/programming.png" width="75px;" height="75px;" alt="programming"/><br /><b>Software Development</b></a></td>
33-
<td align="center"><a href="#python"><img src="images/python.png" width="80px;" height="75px;" alt="Python"/><br /><b>Python</b></a></td>
33+
<td align="center"><a href="https://github.com/bregman-arie/python-exercises"><img src="images/python.png" width="80px;" height="75px;" alt="Python"/><br /><b>Python</b></a></td>
3434
<td align="center"><a href="#go"><img src="images/Go.png" width="75px;" height="75px;" alt="go"/><br /><b>Go</b></a></td>
3535
<td align="center"><a href="exercises/shell/README.md"><img src="images/bash.png" width="70px;" height="75px;" alt="Bash"/><br /><b>Shell Scripting</b></a></td>
3636
<td align="center"><a href="exercises/kubernetes/README.md"><img src="images/kubernetes.png" width="75px;" height="75px;" alt="kubernetes"/><br /><b>Kubernetes</b></a></td>
@@ -2840,263 +2840,6 @@ Yes, it's a operating-system-level virtualization, where the kernel is shared an
28402840
The introduction of virtual machines allowed companies to deploy multiple business applications on the same hardware while each application is separated from each other in secured way, where each is running on its own separate operating system.
28412841
</b></details>
28422842

2843-
## Python
2844-
2845-
### Python Exercises
2846-
2847-
|Name|Topic|Objective & Instructions|Solution|Comments|
2848-
|--------|--------|------|----|----|
2849-
| Identify the data type | Data Types | [Exercise](exercises/python/data_types.md) | [Solution](exercises/python/solutions/data_types_solution.md)
2850-
| Identify the data type - Advanced | Data Types | [Exercise](exercises/python/advanced_data_types.md) | [Solution](exercises/python/solutions/advanced_data_types_solution.md)
2851-
| Reverse String | Strings | [Exercise](exercises/python/reverse_string.md) | [Solution](exercises/python/solutions/reverse_string.md)
2852-
| Compress String | Strings | [Exercise](exercises/python/compress_string.md) | [Solution](exercises/python/solutions/compress_string.md)
2853-
2854-
### Python Self Assessment
2855-
2856-
<details>
2857-
<summary>What are some characteristics of the Python programming language?</summary><br><b>
2858-
2859-
```
2860-
1. It is a high level general purpose programming language created in 1991 by Guido Van Rosum.
2861-
2. The language is interpreted, being the CPython (Written in C) the most used/maintained implementation.
2862-
3. It is strongly typed. The typing discipline is duck typing and gradual.
2863-
4. Python focuses on readability and makes use of whitespaces/identation instead of brackets { }
2864-
5. The python package manager is called PIP "pip installs packages", having more than 200.000 available packages.
2865-
6. Python comes with pip installed and a big standard library that offers the programmer many precooked solutions.
2866-
7. In python **Everything** is an object.
2867-
```
2868-
</b></details>
2869-
2870-
<details>
2871-
<summary>What built-in types Python has?</summary><br><b>
2872-
2873-
List
2874-
Dictionary
2875-
Set
2876-
Numbers (int, float, ...)
2877-
String
2878-
Bool
2879-
Tuple
2880-
Frozenset
2881-
</b></details>
2882-
2883-
<details>
2884-
<summary>What is mutability? Which of the built-in types in Python are mutable?</summary><br><b>
2885-
2886-
Mutability determines whether you can modify an object of specific type.
2887-
2888-
The mutable data types are:
2889-
2890-
List
2891-
Dictionary
2892-
Set
2893-
2894-
The immutable data types are:
2895-
2896-
Numbers (int, float, ...)
2897-
String
2898-
Bool
2899-
Tuple
2900-
Frozenset
2901-
</b></details>
2902-
2903-
#### Python - Booleans
2904-
2905-
<details>
2906-
<summary>What is the result of each of the following?
2907-
2908-
- 1 > 2
2909-
- 'b' > 'a'
2910-
* 1 == 'one'
2911-
- 2 > 'one'</summary><br><b>
2912-
2913-
* False
2914-
* True
2915-
* False
2916-
* TypeError
2917-
</b></details>
2918-
2919-
<details>
2920-
<summary>What is the result of `bool("")`? What about `bool(" ")`? Explain</summary><br><b>
2921-
2922-
bool("") -> evaluates to False<br>
2923-
bool(" ") -> evaluates to True
2924-
</b></details>
2925-
2926-
<details>
2927-
<summary>What is the result of running <code>[] is not []</code>? explain the result</summary><br><b>
2928-
2929-
It evaluates to True.<br>
2930-
The reason is that the two created empty list are different objects. `x is y` only evaluates to true when x and y are the same object.
2931-
</b></details>
2932-
2933-
<details>
2934-
<summary>What is the result of running <code>True-True</code>?</summary><br><b>
2935-
2936-
0
2937-
</b></details>
2938-
2939-
#### Python - Strings
2940-
2941-
<details>
2942-
<summary>True or False? String is an immutable data type in Python</summary><br><b>
2943-
2944-
True
2945-
</b></details>
2946-
2947-
<details>
2948-
<summary>How to check if a string starts with a letter?</summary><br><b>
2949-
2950-
Regex:
2951-
2952-
```
2953-
import re
2954-
if re.match("^[a-zA-Z]+.*", string):
2955-
```
2956-
2957-
string built-in:
2958-
2959-
```
2960-
if string and string[0].isalpha():
2961-
```
2962-
</b></details>
2963-
2964-
<details>
2965-
<summary>How to check if all characters in a given string are digits?</summary><br><b>
2966-
2967-
`string.isdigit`
2968-
</b></details>
2969-
2970-
<details>
2971-
<summary>How to remove trailing slash ('/') from a string?</summary><br><b>
2972-
2973-
`string.rstrip('/')`
2974-
</b></details>
2975-
2976-
<details>
2977-
<summary>What is the result of of each of the following?
2978-
2979-
- "abc"*3
2980-
- "abc"*2.5
2981-
- "abc"*2.0
2982-
- "abc"*True
2983-
- "abc"*False</summary><br><b>
2984-
2985-
* abcabcabc
2986-
* TypeError
2987-
* TypeError
2988-
* "abc"
2989-
* ""
2990-
</b></details>
2991-
2992-
<details>
2993-
<summary>Improve the following code:
2994-
2995-
```
2996-
char = input("Insert a character: ")
2997-
if char == "a" or char == "o" or char == "e" or char =="u" or char == "i":
2998-
print("It's a vowel!")
2999-
```
3000-
</summary><br><b>
3001-
3002-
```
3003-
char = input("Insert a character: ") # For readablity
3004-
if lower(char[0]) in "aieou": # Takes care of multiple characters and separate cases
3005-
print("It's a vowel!")
3006-
```
3007-
OR
3008-
```
3009-
if lower(input("Insert a character: ")[0]) in "aieou": # Takes care of multiple characters and small/Capital cases
3010-
print("It's a vowel!")
3011-
```
3012-
</b></details>
3013-
3014-
#### Python - Functions
3015-
3016-
<details>
3017-
<summary>How to define a function with Python?</summary><br><b>
3018-
Using the `def` keyword. For Examples:
3019-
3020-
```
3021-
def sum(a, b):
3022-
return (a + b)
3023-
```
3024-
</b></details>
3025-
3026-
<details>
3027-
<summary>In Python, functions are first-class objects. What does it mean?</summary><br><b>
3028-
3029-
In general, first class objects in programming languages are objects which can be assigned to variable, used as a return value and can be used as arguments or parameters.<br>
3030-
In python you can treat functions this way. Let's say we have the following function
3031-
3032-
```
3033-
def my_function():
3034-
return 5
3035-
```
3036-
3037-
You can then assign a function to a variables like this `x = my_function` or you can return functions as return values like this `return my_function`
3038-
</b></details>
3039-
3040-
#### Python - Integer
3041-
3042-
<details>
3043-
<summary>Write a function to determine if a number is a Palindrome</summary><br><b>
3044-
3045-
- Code:
3046-
3047-
```
3048-
from typing import Union
3049-
3050-
def isNumberPalindrome(number: Union[int, str]) -> bool:
3051-
if isinstance(number, int):
3052-
number = str(number)
3053-
return number == number[::-1]
3054-
3055-
print(isNumberPalindrome("12321"))
3056-
```
3057-
3058-
- Using Python3.10 that accepts using bitwise operator '|'.
3059-
3060-
```
3061-
def isNumberPalindrome(number: int | str) -> bool:
3062-
if isinstance(number, int):
3063-
number = str(number)
3064-
return number == number[::-1]
3065-
3066-
print(isNumberPalindrome("12321"))
3067-
```
3068-
3069-
Note: Using slicing to reverse a list could be slower than other options like `reversed` that return an iterator.
3070-
3071-
- Result:
3072-
3073-
```
3074-
True
3075-
```
3076-
3077-
</b></details>
3078-
3079-
#### Python - Loops
3080-
3081-
<details>
3082-
<summary>What is the result of the following block of code?
3083-
3084-
```
3085-
x = ['a', 'b', 'c']
3086-
for i in x:
3087-
if i == 'b':
3088-
x = ['z', 'y']
3089-
print(i)
3090-
```
3091-
</summary><br><b>
3092-
3093-
```
3094-
a
3095-
b
3096-
c
3097-
```
3098-
</b></details>
3099-
31002843
#### Python - OOP
31012844

31022845
<details>
@@ -3457,12 +3200,6 @@ List, as opposed to a tuple, is a mutable data type. It means we can modify it a
34573200
`x.append(2)`
34583201
</b></details>
34593202

3460-
<details>
3461-
<summary>How to check how many items a list contains?</summary><br><b>
3462-
3463-
`len(sone_list)`
3464-
</b></details>
3465-
34663203
<details>
34673204
<summary>How to get the last element of a list?</summary><br><b>
34683205

@@ -3483,30 +3220,6 @@ Don't use `append` unless you would like the list as one item.
34833220
`my_list[0:3] = []`
34843221
</b></details>
34853222

3486-
<details>
3487-
<summary>How do you get the maximum and minimum values from a list?</summary><br><b>
3488-
3489-
```
3490-
Maximum: max(some_list)
3491-
Minimum: min(some_list)
3492-
```
3493-
</b></details>
3494-
3495-
<details>
3496-
<summary>How to get the top/biggest 3 items from a list?</summary><br><b>
3497-
3498-
```
3499-
sorted(some_list, reverse=True)[:3]
3500-
```
3501-
3502-
Or
3503-
3504-
```
3505-
some_list.sort(reverse=True)
3506-
some_list[:3]
3507-
```
3508-
</b></details>
3509-
35103223
<details>
35113224
<summary>How to insert an item to the beginning of a list? What about two items?</summary><br><b>
35123225

@@ -3860,14 +3573,6 @@ with open('file.txt', 'w') as file:
38603573
```
38613574
</b></details>
38623575

3863-
<details>
3864-
<summary>How to print the 12th line of a file?</summary><br><b>
3865-
</b></details>
3866-
3867-
<details>
3868-
<summary>How to reverse a file?</summary><br><b>
3869-
</b></details>
3870-
38713576
<details>
38723577
<summary>Sum all the integers in a given file</summary><br><b>
38733578
</b></details>
@@ -3965,10 +3670,6 @@ with open('file.json', 'w') as f:
39653670
Using the re module
39663671
</b></details>
39673672

3968-
<details>
3969-
<summary>How to substitute the string "green" with "blue"?</summary><br><b>
3970-
</b></details>
3971-
39723673
<details>
39733674
<summary>How to find all the IP addresses in a variable? How to find them in a file?</summary><br><b>
39743675
</b></details>

0 commit comments

Comments
 (0)