Featured Post

SQL Interview Success: Unlocking the Top 5 Frequently Asked Queries

Image
 Here are the five top commonly asked SQL queries in the interviews. These you can expect in Data Analyst, or, Data Engineer interviews. Top SQL Queries for Interviews 01. Joins The commonly asked question pertains to providing two tables, determining the number of rows that will return on various join types, and the resultant. Table1 -------- id ---- 1 1 2 3 Table2 -------- id ---- 1 3 1 NULL Output ------- Inner join --------------- 5 rows will return The result will be: =============== 1  1 1   1 1   1 1    1 3    3 02. Substring and Concat Here, we need to write an SQL query to make the upper case of the first letter and the small case of the remaining letter. Table1 ------ ename ===== raJu venKat kRIshna Solution: ========== SELECT CONCAT(UPPER(SUBSTRING(name, 1, 1)), LOWER(SUBSTRING(name, 2))) AS capitalized_name FROM Table1; 03. Case statement SQL Query ========= SELECT Code1, Code2,      CASE         WHEN Code1 = 'A' AND Code2 = 'AA' THEN "A" | "A

How to Use List Function in Python

Here's is an answer to calculate the length of the repeated lists. LIST is a principle data type in Python that holds a list of values. Usually strings.

List() Function the Real Usage

You can do various operations with Lists. The best examples are REPEAT, APPEND, INSERT, EXTEND, COUNT. Still more you can do.


Note: This question is from a test recently held by an HR company. HR firms usually ask to take an online test to filter the job-seekers.

You can find list length using list() and len() functions


IN THIS PAGE


1. Question
2. How to Find Length


Interview Question 

The '* 2' says times the list is repeated. In this question, they have given '2' times.


my_list = ['srini', 'seetha', 'rao']
b = len(list(list(list(list(list(my_list*2))))))
Print (b)


Select Answer

1. 5
2. 6
3. 7
4. None

Explanation:

  • In the first step, the '*' says, you repeated the List two times.
  • It confuses the test-taker since they have given multiple functions of the list().

How to get Length


You can code the way I did. So that you can get the length correctly. So, the answer to the question is '6'. The List is repeated twice. There's no effect of multiple lists on the list.


Result (Ubuntu Linux OS)


At the command level, the given question entered. After pressing enter, it showed the result as '6'. That means the list (which has initially '3' elements') doubled. So the list length is now '6'.


Result of Python List

References

  1. Here're the best examples on Python List
  2. Here's the complete list for your reference.

Comments

Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

Explained Ideal Structure of Python Class

How to Check Kafka Available Brokers