Professional Documents
Culture Documents
What is the output of the following code snippet? def foo(x, y=[]):
y.append(x)
return y
print(foo(2))
print(foo(3))
How to implement a function to check if two strings are anagrams of eachother.def is_anagram(string1, string2):
return sorted(string1.lower()) == sorted(string2.lower())
Write a Python function to check if a string is a pangram (contains all the letters of the alphabet).
Questions(SQL)
What is a recursive SQL query and when would you use it?
Explain the concept of index fragmentation and its impact on database performance.
Explain the concept of query optimization in SQL and discuss techniques to improve query performance.
Explain the concept of database locking and discuss different types of locks in SQL.
Questions(Power BI)
What is the difference between calculated columns and calculated measures in Power BI?
Explain the concept of data modeling in Power BI?
How can you optimize the performance of Power BI reports and dashboards?
Answer Explanation
y.append(x)
def
reverse_string(input_string):
reversed_string = ""
for i in
range(len(input_string) - 1, -
1, -1):
reversed_string +=
input_string[i]
return reversed_string
input_str = "Hello, World!"
reversed_str = !dlroW ,olleH
reverse_string(input_str)
print(reversed_str) The function iterates over the input
input_str = "Hello, World!" string in reverse order and constructs a
reversed_str = new string by appending the characters
reverse_string(input_str) from the last index to the first index,
print(reversed_str) effectively reversing the string.
string1 = "listen"
This is the function string2 = "silent"
declaration. It takes in two
parameters, string1 and if is_anagram(string1, string2):
string2, which represent the print("The strings are anagrams.")
two strings we want to else:
check for an anagram print("The strings are not
relationship. anagrams.")
import string
def
is_pangram(input_string):
alphabet =
set(string.ascii_lowercase)
letters = In this example, we import the string
set(input_string.lower()) module and create a set alphabet from
string.ascii_lowercase. The resulting set
return letters >= alphabet contains all the lowercase letters of the
input_str = "The quick English alphabet.
brown fox jumps over the
lazy dog" Later in the function, we compare the
set letters (containing the characters
if is_pangram(input_str): from the input string) with the set
print("The string is a alphabet to determine if letters is a
pangram.") superset of alphabet. This comparison
else: helps determine whether the input
print("The string is not a string is a pangram, indicating if it
pangram.") contains all the letters of the alphabet.
SELECT A.CustomerName AS
A self join is a regular join, CustomerName1, B.CustomerName AS
but the table is joined with CustomerName2, A.City
itself. It's basically used FROM Customers A, Customers B
where there is any WHERE A.CustomerID <> B.CustomerID
relationship between rows AND A.City = B.City
stored in the same table. ORDER BY A.City;