Featured Post

Top Questions People Ask About Pandas, NumPy, Matplotlib & Scikit-learn — Answered!

Image
 Whether you're a beginner or brushing up on your skills, these are the real-world questions Python learners ask most about key libraries in data science. Let’s dive in! 🐍 🐼 Pandas: Data Manipulation Made Easy 1. How do I handle missing data in a DataFrame? df.fillna( 0 ) # Replace NaNs with 0 df.dropna() # Remove rows with NaNs df.isna(). sum () # Count missing values per column 2. How can I merge or join two DataFrames? pd.merge(df1, df2, on= 'id' , how= 'inner' ) # inner, left, right, outer 3. What is the difference between loc[] and iloc[] ? loc[] uses labels (e.g., column names) iloc[] uses integer positions df.loc[ 0 , 'name' ] # label-based df.iloc[ 0 , 1 ] # index-based 4. How do I group data and perform aggregation? df.groupby( 'category' )[ 'sales' ]. sum () 5. How can I convert a column to datetime format? df[ 'date' ] = pd.to_datetime(df[ 'date' ]) ...

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

SQL Query: 3 Methods for Calculating Cumulative SUM

5 SQL Queries That Popularly Used in Data Analysis

Big Data: Top Cloud Computing Interview Questions (1 of 4)