diff --git a/README.md b/README.md index d95b01d..b49ce5b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ :information_source:  This repository contains questions on various DevOps and SRE related topics -:bar_chart:  There are currently **733** questions +:bar_chart:  There are currently **738** questions :books:  To learn more about DevOps check the resources in [DevOpsBit.com](https://devopsbit.com) @@ -2939,6 +2939,15 @@ sorted(some_list, reverse=True)[:3] ``` +
+Convert every string to an integer: [['1', '2', '3'], ['4', '5', '6']]
+ +``` +nested_li = [['1', '2', '3'], ['4', '5', '6']] +[[int(x) for x in li] for li in nested_li] +``` +
+
How to merge two sorted lists into one sorted list?
@@ -3003,6 +3012,29 @@ If we call it 3 times, what would be the result each call?
How to iterate over a list in reverse order?
+ +Method 1 +``` +for i in reversed(li): + ... +``` + +Method 2 +``` +for i in li[::-1]: + ... +``` +
+ +
+Combine [1, 2, 3] and ['x', 'y', 'z'] so the result is [(1, 'x'), (2, 'y'), (3, 'z')]
+ +``` +nums = [1, 2, 3] +letters = ['x', 'y', 'z'] + +list(zip(nums, letters)) +```
#### Dictionaries @@ -3116,6 +3148,34 @@ y = ''.join(set(x))
Find all the permutations of a given string
+ +``` +def permute_string(string): + + if len(string) == 1: + return [string] + + permutations = [] + for i in range(len(string)): + swaps = permute_string(string[:i] + string[(i+1):]) + for swap in swaps: + permutations.append(string[i] + swap) + + return permutations + +print(permute_string("abc")) +``` + +Short way (but probably not acceptable in interviews): + +``` +from itertools import permutations + +[''.join(p) for p in permutations("abc")] +``` + +Detailed answer can be found here: http://codingshell.com/python-all-string-permutations +
@@ -3126,6 +3186,16 @@ y = ''.join(set(x)) Find the frequency of each character in string
+
+Given the string (which represents a matrix) "1 2 3\n4 5 6\n7 8 9" create rows and colums variables (should contain integers, not strings)
+ +``` +matrix = "1 2 3\n4 5 6\n7 8 9" +rows = [ [int(x) for x in li if x != ' '] for li in matrix.split("\n")] +colums = list(zip(*(rows))) +``` +
+
What is the result of each of the following? ``` @@ -3293,10 +3363,14 @@ def sum(a, b): ``` li = [] -for i in range(1,10): +for i in range(1, 10): li.append(i) ```
+ +``` +[for i in in range(1, 10)] +```
@@ -3345,7 +3419,7 @@ What would be the result of is_int(2) and is_int(False)? Why one shouldn't use assert in non-test/production code?
-##### Flask +#### Flask
You wrote you have experience with Django/Flask. Can you describe what is Django/Flask and how you have used it? Why Flask and not Djano? (or vice versa)
@@ -3359,6 +3433,31 @@ What would be the result of is_int(2) and is_int(False)? How do you manage DB integration?
+#### zip + +
+Given x = [1, 2, 3], what is the result of list(zip(x))?
+ +``` +[(1,), (2,), (3,)] +``` +
+ +
+What is the result of each of the following: + +``` +list(zip(range(5), range(50), range(50))) +list(zip(range(5), range(50), range(-2))) +``` +
+ +``` +[(0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4)] +[] +``` +
+ #### :star: Advanced