Skip to content

thangakumard/01_Datastructure_Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

01_Datastructure_Python

🔹 1. Basic Data Types (int, float, bool, str)

Conceptual

  1. Difference between int and float? | Feature | int | float | | ---------- | ---------------- | ---------------------------- | | Stores | Whole numbers | Decimal numbers | | Example | 10, -5 | 10.5, -3.14 | | Precision | Exact | Approximate (floating point) | | Memory | Less | More | | Operations | Faster | Slightly slower | | Conversion | int(5.9)5 | float(5)5.0 |

Key point: int has no decimal part, float always has decimal precision.

  1. What is implicit vs explicit type conversion?

    🔹 Implicit (Automatic)

    Python automatically converts one type to another. a = 10 # int b = 2.5 # float c = a + b # Python converts int → float print(c) # 12.5

    ✔ Done by Python ✔ No data loss usually

    🔹 Explicit (Manual)

    The programmer converts type manually.

    x = "100" y = int(x) print(y) # 100

    ✔ Done by developer ✔ Used when types mismatch

  2. How does Python handle integer overflow? Python DOES NOT overflow integers. It supports arbitrary-precision integers.

    x = 10**100 print(x)

    ✔ No limit on size ✔ Memory increases dynamically ✔ Slower for extremely large numbers Unlike C/Java: No wrap-around or overflow error.

  3. What is truthy and falsy in Python? 🔹 Falsy values

    Evaluated as False in condition:

    False 0 0.0 '' [] {} () None

    Example:

    if []: print("True") else: print("False") # Executes

    🔹 Truthy values

    Everything else is truthy:

    1 "hello" [1,2] {'a':1}

  4. Difference between == and is? == Compares values is Compares memory location (identity)

Practical

  1. Convert float 12.9 to int. What happens?
  2. Convert string "123" to integer safely.
  3. Reverse a string without using slicing.
  4. Count vowels in a string.
  5. Check if a number is palindrome.

🔹 2. Strings

DataType & Conversion

  1. Convert list of chars to string.
  2. Convert string to list of words.
  3. Difference between join() and split()?
  4. Convert "True" to boolean – is it possible?
  5. Remove duplicates from string.

Looping

  1. Print each character using loop.
  2. Find frequency of each character.
  3. Reverse words in a sentence.
  4. Print only digits from string.
  5. Find longest word in sentence.

🔹 3. Lists

DataType

  1. Difference between list and tuple.
  2. What is shallow vs deep copy?
  3. Time complexity of append, pop?
  4. Difference between extend() and append()?
  5. When to use list comprehension?

Looping

  1. Print even numbers from list.
  2. Reverse list using loop.
  3. Find second largest number.
  4. Remove duplicates using loop.
  5. Count frequency of elements.

Type Conversion

  1. Convert list → tuple.
  2. Convert list → set.
  3. Convert list of strings → list of ints.
  4. Convert nested list to flat list.
  5. Convert list to dictionary.

🔹 4. Tuples

  1. Why tuples are immutable?
  2. Convert tuple → list.
  3. Find index of element.
  4. Loop through tuple.
  5. Swap values using tuple unpacking.
  6. Count occurrences of element.
  7. Convert tuple of pairs → dict.
  8. Remove duplicates from tuple.
  9. Sort tuple.
  10. Difference between (1) and (1,)?

🔹 5. Sets

  1. Difference between set and list.
  2. Why set doesn’t allow duplicates?
  3. Convert list → set.
  4. Find union, intersection, difference.
  5. Loop through set.
  6. Check subset and superset.
  7. Remove elements safely.
  8. Convert set → list.
  9. Find common elements between 2 lists.
  10. When to use frozenset?

🔹 6. Dictionaries

DataType

  1. Difference between dict and OrderedDict.
  2. Keys rules in dictionary.
  3. Can list be key? Why?
  4. Difference between get() and [].
  5. How to merge two dicts?

Looping

  1. Loop keys only.
  2. Loop values only.
  3. Loop key-value pairs.
  4. Find max value key.
  5. Count word frequency using dict.

Type Conversion

  1. Convert list of tuples → dict.
  2. Convert dict → list of keys.
  3. Convert dict → list of values.
  4. Convert dict → tuple.
  5. Sort dictionary by values.

🔹 7. Looping (for, while)

  1. Difference between for & while.
  2. What is infinite loop?
  3. Use of break & continue.
  4. Print numbers 1–100.
  5. Print prime numbers.
  6. Fibonacci series.
  7. Factorial using loop.
  8. Nested loops example.
  9. Pattern printing.
  10. Reverse number using loop.

🔹 8. Type Conversion (Casting)

  1. int → float
  2. float → int
  3. str → int (safe way)
  4. list → tuple
  5. tuple → list
  6. list → set
  7. set → list
  8. dict → list
  9. list → dict
  10. bool → int

🔹 9. Mixed Data Structure Problems

  1. Flatten nested list.
  2. Remove duplicate dictionaries.
  3. Sort list of tuples.
  4. Group anagrams.
  5. Convert list of dicts → single dict.
  6. Find common keys in dicts.
  7. Merge lists without duplicates.
  8. Count elements in nested list.
  9. Find max value in dict of lists.
  10. Reverse dictionary.

🔹 10. Advanced Logic

  1. Check if list is sorted.
  2. Rotate list k times.
  3. Find missing number.
  4. Find duplicate number.
  5. Two sum problem.
  6. Intersection of 3 lists.
  7. Find pairs with sum.
  8. Convert Roman → integer.
  9. String compression.
  10. Balanced parentheses.

🔹 11. Tricky Output Questions

  1. What is output of:
print(bool("False"))
a = [1,2,3]
b = a
b.append(4)
print(a)
print(type({}))
print(set([1,1,2,2]))
print(1 == True)

🔹 12. Real-World Scenario Questions

  1. Read CSV → dict.
  2. Parse JSON → Python object.
  3. Remove null values from list.
  4. Count API response status codes.
  5. Convert input string → number safely.

🔹 Bonus (Interview Favorite)

  1. Difference between mutable & immutable?
  2. Memory behavior of lists vs tuples.
  3. When to use set vs dict?
  4. Time complexity of searching in list vs set.
  5. Why dict lookup is fast?

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages