---
# System prepended metadata

title: Untitled

---

``` sql

1) Get users who attended some activity more than twice.

>> SELECT * FROM users;
user_id  username
1        John Doe
2        Jane Don
3        Alice Jones
4        Lisa Romero


>> SELECT * FROM training_details;
user_training_id  user_id  training_id  training_date
1                 1        1            "2015-08-02"
6                 1        1            "2015-08-02"
9                 1        4            "2015-08-03"
13                1        1            "2015-08-02"

--------------------------------------------
SELECT username, COUNT(training_id) as NUMBER_OF_TRAININGS
FROM training_details 
INNER JOIN users ON users.user_id = training_details.user_id
GROUP BY username, training_id
HAVING NUMBER_OF_TRAININGS > 1

```
``` python

2) Implement a group_by_owners that:
Accepts a dictionary containing the file owner name for each file name.
Returns a dictionary containing a list of file names for each owner name, in any order.
For example, dictionary:
{
    'Input.txt': 'Randy',
    'Code.py': 'Stan',
    'Output.txt': 'Randy'
}
​
the group_by_owners function should return:
{
    'Randy': ['Input.txt', 'Output.txt'],
    'Stan': ['Code.py']
}

--------------------------------------------
import collections
def group_by_owners(file_user_map):
    result = collections.defaultdict(list)
    for fn, un in file_user_map.items():
        result[un].append(fn)
    return result

``` 

``` python
3) Sort list of objects by age field in ascending order


Input:
animals = [
    {'type': 'penguin', 'name': 'Stephanie', 'age': 8},
    {'type': 'elephant', 'name': 'Devon', 'age': 3},
    {'type': 'puma', 'name': 'Moe', 'age': 5},
]

Output:
sorted_animals = [
    {'type': 'elephant', 'name': 'Devon', 'age': 3},
    {'type': 'puma', 'name': 'Moe', 'age': 5},
    {'type': 'penguin', 'name': 'Stephanie', 'age': 8}
]
--------------------------------------------



```
``` python

4) What will be the output of the following code snippet?

class Person:
    def __init__(self, id):
        self.id = id

sam = Person(100)
sam.__dict__['age'] = 49
print(sam.age + len(sam.__dict__))
--------------------------------------------



```
``` python

5) What will be the output of the following code snippet?

class A:
    def __init__(self):
        self.calcI(30)
        print("i from A is", self.i)
        
    def calcI(self, i):
        self.i = 2 * i
        
class B(A):
    def __init__(self):
        super().__init__()
        
    def calcI(self, i):
        self.i = 3 * i
​
b = B()
--------------------------------------------


```
``` python
6) Write a code snippet that returns all pairs of numbers that return sum of 10
[0, -1, 9, 9, 1, 3, 6, 7, 1]
--------------------------------------------


```