Skip to content

Commit b6fc433

Browse files
author
abregman
committed
Add a couple of Python questions
1 parent 37684a9 commit b6fc433

File tree

1 file changed

+89
-59
lines changed

1 file changed

+89
-59
lines changed

README.md

Lines changed: 89 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
:information_source:  This repository contains questions on various DevOps and SRE related topics
44

5-
:bar_chart:  There are currently **720** questions
5+
:bar_chart:  There are currently **725** questions
66

77
:books:  To learn more about DevOps check the resources in [DevOpsBit.com](https://devopsbit.com)
88

@@ -2509,6 +2509,14 @@ Setting the replicas to 0 will shut down the process. Now start it with `kubectl
25092509
<summary>What programming language do you prefer to use for DevOps related tasks? Why specifically this one?</summary><br><b>
25102510
</b></details>
25112511

2512+
<details>
2513+
<summary>Explain expressions and statements</summary><br><b>
2514+
2515+
An expression is anything that results in a value (even if the value is None). Basically, any sequence of literals so, you can say that a string, integer, list, ... are all expressions.
2516+
2517+
Statements are instructions executed by the interpreter like variable assignments, for loops and conditionals (if-else).
2518+
</b></details>
2519+
25122520
<details>
25132521
<summary>What is Object Oriented Programming? Why is it important?</summary><br><b>
25142522
</b></details>
@@ -2686,10 +2694,6 @@ def my_function():
26862694
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`
26872695
</b></details>
26882696

2689-
<details>
2690-
<summary>Explain expressions and statements</summary><br><b>
2691-
</b></details>
2692-
26932697
<details>
26942698
<summary>What is PEP8? Give an example of 3 style guidelines</summary><br><b>
26952699

@@ -2704,6 +2708,13 @@ PEP8 is a list of coding conventions and style guidelines for Python
27042708
5. Use 4 spaces per indentation level
27052709
</b></details>
27062710

2711+
<details>
2712+
<summary>What is the result of running <code>[] is not []</code>? explain the result</summary><br><b>
2713+
2714+
It evaluates to True.<br>
2715+
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.
2716+
</b></details>
2717+
27072718
<details>
27082719
<summary>Explain inheritance and how to use it in Python</summary><br><b>
27092720

@@ -2768,16 +2779,13 @@ bruno.bark()
27682779
Calling super() calls the Base method, thus, calling super().__init__() we called the Animal __init__.
27692780
27702781
There is a more advanced python feature called MetaClasses that aid the programmer to directly control class creation.
2771-
27722782
```
2773-
27742783
</b></details>
27752784

27762785
<details>
27772786
<summary> What is an error? What is an exception? What types of exceptions are you familiar with?</summary><br><b>
27782787

27792788
```
2780-
27812789
# Note that you generally don't need to know the compiling process but knowing where everything comes from
27822790
# and giving complete answers shows that you truly know what you are talking about.
27832791
@@ -2834,18 +2842,19 @@ Generally, every compiling process have a two steps.
28342842
division(100, 2)
28352843
28362844
>>> __main__.DividedBy2Error: I dont want you to divide by 2!
2837-
28382845
```
2839-
2840-
28412846
</b></details>
28422847

28432848
<details>
28442849
<summary>Explain Exception Handling and how to use it in Python</summary><br><b>
28452850
</b></details>
28462851

28472852
<details>
2848-
<summary>Explain Exception Handling and how to use it in Python</summary><br><b>
2853+
<summary>What _ is used for in Python?</summary><br><b>
2854+
2855+
1. Translation lookup in i18n
2856+
2. Hold the result of the last executed expression or statement in the interactive interpreter.
2857+
3. As a general purpose "throwaway" variable name. For example: x, y, _ = get_data() (x and y are used but since we don't care about third variable, we "threw it away").
28492858
</b></details>
28502859

28512860
<details>
@@ -2861,11 +2870,10 @@ Generally, every compiling process have a two steps.
28612870
</b></details>
28622871

28632872
<details>
2864-
<summary>How to extract the unique characters from a string? for example given the input "itssssssameeeemarioooooo" the output will be "mrtisaoe"</summary><br><b>
2873+
<summary>How do you swap values between two variables?</summary><br><b>
28652874

28662875
```
2867-
x = "itssssssameeeemarioooooo"
2868-
y = ''.join(set(x))
2876+
x, y = y, x
28692877
```
28702878
</b></details>
28712879

@@ -2887,21 +2895,10 @@ def return_sum():
28872895
```
28882896
</b></details>
28892897

2890-
<details>
2891-
<summary>How to merge two sorted lists into one sorted list?</summary><br><b>
2892-
</b></details>
2893-
2894-
<details>
2895-
<summary>How to merge two dictionaries?</summary><br><b>
2896-
</b></details>
2898+
#### Lists
28972899

28982900
<details>
2899-
<summary>How do you swap values between two variables?</summary><br><b>
2900-
2901-
```
2902-
x, y = y, x
2903-
```
2904-
2901+
<summary>How to merge two sorted lists into one sorted list?</summary><br><b>
29052902
</b></details>
29062903

29072904
<details>
@@ -2947,23 +2944,37 @@ This one might look more convulated but hey, one liners.
29472944
def is_unique4(l:list) -> bool:
29482945
return all(map(lambda x: l.count(x) < 2, l))
29492946
```
2950-
29512947
</details>
29522948

29532949
<details>
2954-
<summary>What _ is used for in Python?</summary><br><b>
2950+
<summary>You have the following function
29552951

2956-
1. Translation lookup in i18n
2957-
2. Hold the result of the last executed expression or statement in the interactive interpreter.
2958-
3. As a general purpose "throwaway" variable name. For example: x, y, _ = get_data() (x and y are used but since we don't care about third variable, we "threw it away").
2952+
```
2953+
def my_func(li = []):
2954+
li.append("hmm")
2955+
print(li)
2956+
```
2957+
2958+
If we call it 3 times, what would be the result each call?
2959+
</summary><br><b>
29592960
</b></details>
29602961

29612962
<details>
2962-
<summary>How to check how much time it took to execute a certain script or block of code?</summary><br><b>
2963+
<summary>How to iterate over a list in reverse order?</summary><br><b>
29632964
</b></details>
29642965

2966+
#### Dictionaries
2967+
29652968
<details>
2966-
<summary>Find all the permutations of a given string</summary><br><b>
2969+
<summary>How to sort a dictionary by values?</summary><br><b>
2970+
</b></details>
2971+
2972+
<details>
2973+
<summary>How to sort a dictionary by keys?</summary><br><b>
2974+
</b></details>
2975+
2976+
<details>
2977+
<summary>How to merge two dictionaries?</summary><br><b>
29672978
</b></details>
29682979

29692980
##### Common Algorithms Implementation
@@ -3050,7 +3061,28 @@ set([food for bro in x for food in bro['food']])
30503061
<summary>What is List Comprehension? Is it better than a typical loop? Why? Can you demonstrate how to use it?</summary><br><b>
30513062
</b></details>
30523063

3053-
#### Practical
3064+
#### Strings
3065+
3066+
<details>
3067+
<summary>How to extract the unique characters from a string? for example given the input "itssssssameeeemarioooooo" the output will be "mrtisaoe"</summary><br><b>
3068+
3069+
```
3070+
x = "itssssssameeeemarioooooo"
3071+
y = ''.join(set(x))
3072+
```
3073+
</b></details>
3074+
3075+
<details>
3076+
<summary>Find all the permutations of a given string</summary><br><b>
3077+
</b></details>
3078+
3079+
<details>
3080+
<summary>How to check if a string contains a sub string?</summary><br><b>
3081+
</b></details>
3082+
3083+
<details>
3084+
<summary>Find the frequency of each character in string</summary><br><b>
3085+
</b></details>
30543086

30553087
<details>
30563088
<summary>How to reverse a string? (e.g. pizza -> azzip)</summary><br><b>
@@ -3073,14 +3105,6 @@ def reverse_string(string):
30733105
```
30743106
</b></details>
30753107

3076-
<details>
3077-
<summary>How to sort a dictionary by values?</summary><br><b>
3078-
</b></details>
3079-
3080-
<details>
3081-
<summary>How to sort a dictionary by keys?</summary><br><b>
3082-
</b></details>
3083-
30843108
<details>
30853109
<summary>Explain data serialization and how do you perform it with Python</summary><br><b>
30863110
</b></details>
@@ -3128,12 +3152,18 @@ the_list.sort(key=lambda x: x[1])
31283152
* filter()</summary><br><b>
31293153
</b></details>
31303154

3155+
#### Debugging
3156+
31313157
<details>
31323158
<summary>How do you debug Python code?</summary><br><b>
31333159

31343160
pdb :D
31353161
</b></details>
31363162

3163+
<details>
3164+
<summary>How to check how much time it took to execute a certain script or block of code?</summary><br><b>
3165+
</b></details>
3166+
31373167
<details>
31383168
<summary>What empty <code>return</code> returns?</summary><br><b>
31393169
</b>
@@ -3207,19 +3237,6 @@ for i in range(1,10):
32073237
</summary><br><b>
32083238
</b></details>
32093239

3210-
<details>
3211-
<summary>You have the following function
3212-
3213-
```
3214-
def my_func(li = []):
3215-
li.append("hmm")
3216-
print(li)
3217-
```
3218-
3219-
If we call it 3 times, what would be the result each call?
3220-
</summary><br><b>
3221-
</b></details>
3222-
32233240
<details>
32243241
<summary>Given the following function
32253242

@@ -3692,9 +3709,22 @@ You can use it for example to control endlines in files. In Windows and Unix bas
36923709
</b></details>
36933710

36943711
<details>
3695-
<summary>How do you discard local file changes?</summary><br><b>
3712+
<summary>How do you discard local file changes? (before commit)</summary><br><b>
3713+
3714+
`git checkout -- <file_name>`
3715+
</b></details>
3716+
3717+
<details>
3718+
<summary>How do you discard local commits?</summary><br><b>
3719+
3720+
`git reset HEAD~1` for removing last commit
3721+
If you would like to also discard the changes you `git reset --hard``
3722+
</b></details>
3723+
3724+
<details>
3725+
<summary>True or False? To remove a file from git but not from the filesystem, one should use <code>git rm </code></summary><br><b>
36963726

3697-
You can use `git checkout -- <file_name>`
3727+
False. If you would like to keep a file on your filesystem, use `git reset <file_name>`
36983728
</b></details>
36993729

37003730
<a name="git-advanced"></a>

0 commit comments

Comments
 (0)