InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How will you access the dataset of a publicly shared spreadsheet in CSV format stored in Google Drive? |
|
Answer» We can use the StringIO module from the io module to read from the Google Drive link and then we can use the PANDAS library using the obtained data source. from io import StringIOimport pandascsv_link = "https://docs.google.com/spreadsheets/d/..."data_source = StringIO.StringIO(requests.get(csv_link).content))dataframe = pd.read_csv(data_source)print(dataframe.head())Conclusion:In this article, we have seen commonly asked interview questions for a python developer. These questions along with regular problem practice sessions will help you crack any python BASED interviews. Over the years, python has gained a lot of POPULARITY amongst the developer’s community due to its simplicity and ABILITY to support powerful computations. Due to this, the demand for good python developers is ever-growing. Nevertheless, to mention, the perks of being a python developer are really good. Along with theoretical knowledge in python, there is an emphasis on the ability to write good quality code as well. So, keep learning and keep practicing problems and without a doubt, you can crack any interviews. Important Resources:
|
|
| 2. |
Write a Program to combine two different dictionaries. While combining, if you find the same keys, you can add the values of these same keys. Output the new dictionary |
|
Answer» We can USE the COUNTER method from the COLLECTIONS module from collections import Counterd1 = {'key1': 50, 'key2': 100, 'key3':200}d2 = {'key1': 200, 'key2': 100, 'key4':300}new_dict = Counter(d1) + Counter(d2)PRINT(new_dict) |
|
| 3. |
Write a Program to convert date from yyyy-mm-dd format to dd-mm-yyyy format. |
|
Answer» We can again USE the re MODULE to convert the DATE string as shown below: import redef transform_date_format(date): return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', date)date_input = "2021-08-01"PRINT(transform_date_format(date_input))You can ALSO use the datetime module as shown below: from datetime import datetimenew_date = datetime.strptime("2021-08-01", "%Y-%m-%d").strftime("%d:%m:%Y")print(new_data) |
|
| 4. |
Write a Program to match a string that has the letter ‘a’ followed by 4 to 8 'b’s. |
|
Answer» We can USE the re module of python to perform regex pattern COMPARISON here. import redef match_text(txt_data): pattern = 'ab{4,8}' if re.search(pattern, txt_data): #search for pattern in txt_data return 'MATCH found' else: return('Match not found')print(match_text("abc")) #prints Match not foundprint(match_text("aabbbbbc")) #prints Match found |
|
| 5. |
Write a Program to solve the given equation assuming that a,b,c,m,n,o are constants: |
|
Answer» ax + by = cmx + ny = o By solving the equation, we GET: a, B, c, m, N, o = 5, 9, 4, 7, 9, 4temp = a*n - b*mif n != 0: X = (c*n - b*o) / temp y = (a*o - m*c) / temp print(str(x), str(y)) |
|
| 6. |
Write a Program to add two integers >0 without using the plus operator. |
|
Answer» We can use bitwise OPERATORS to ACHIEVE this. def add_nums(num1, num2): while num2 != 0: data = num1 & num2 num1 = num1 ^ num2 num2 = data << 1 return num1print(add_nums(2, 10)) |
|
| 7. |
Write a program to check and return the pairs of a given array A whose sum value is equal to a target value N. |
|
Answer» This can be done easily by using the PHENOMENON of hashing. We can use a hash map to check for the current value of the ARRAY, X. If the map has the value of (N-x), then there is our pair. def print_pairs(arr, N): # hash set hash_set = set() for i in range(0, len(arr)): val = N-arr[i] if (val in hash_set): #check if N-x is there in set, print the pair print("Pairs " + str(arr[i]) + ", " + str(val)) hash_set.add(arr[i])# driver codearr = [1, 2, 40, 3, 9, 4]N = 3print_pairs(arr, N) |
|
| 8. |
Write a program for counting the number of every character of a given text file. |
|
Answer» The IDEA is to USE collections and pprint MODULE as shown below: import collectionsimport pprintwith OPEN("sample_file.txt", 'r') as DATA: count_data = collections.Counter(data.read().upper()) count_value = pprint.pformat(count_data)print(count_value) |
|
| 9. |
WAP (Write a program) which takes a sequence of numbers and check if all numbers are unique. |
|
Answer» You can do this by converting the list to SET by USING set() method and comparing the length of this set with the length of the original list. If FOUND EQUAL, return TRUE. def check_distinct(data_list): if len(data_list) == len(set(data_list)): return True else: return False;print(check_distinct([1,6,5,8])) #Prints Trueprint(check_distinct([2,2,5,5,7,8])) #Prints False |
|
| 10. |
Write python function which takes a variable number of arguments. |
|
Answer» A FUNCTION that TAKES variable arguments is CALLED a function prototype. Syntax: def function_name(*arg_list)For EXAMPLE: def func(*var): for i in var: print(i)func(1)func(20,1,6)The * in the function argument REPRESENTS variable arguments in the function. |
|