|
| 1 | +# 500+ Python Exercises - Part 2 |
| 2 | + |
| 3 | +## Section 7: Lists (50 exercises) |
| 4 | + |
| 5 | +### Easy (1-18) |
| 6 | + |
| 7 | +1. Create empty list and print it |
| 8 | +2. Create list with 5 integers |
| 9 | +3. Create list with mixed data types |
| 10 | +4. Access first element of list |
| 11 | +5. Access last element of list |
| 12 | +6. Access element at index 3 |
| 13 | +7. Find length of list |
| 14 | +8. Append element to end of list |
| 15 | +9. Insert element at specific position |
| 16 | +10. Remove element by value |
| 17 | +11. Remove element by index |
| 18 | +12. Pop last element from list |
| 19 | +13. Find index of element |
| 20 | +14. Count occurrence of element |
| 21 | +15. Sort list in ascending order |
| 22 | +16. Sort list in descending order |
| 23 | +17. Reverse a list |
| 24 | +18. Copy a list |
| 25 | + |
| 26 | +### Medium (19-35) |
| 27 | + |
| 28 | +19. Find sum of all elements |
| 29 | +20. Find maximum element |
| 30 | +21. Find minimum element |
| 31 | +22. Find average of elements |
| 32 | +23. Count even numbers in list |
| 33 | +24. Count odd numbers in list |
| 34 | +25. Find all prime numbers in list |
| 35 | +26. Remove duplicates from list |
| 36 | +27. Merge two lists |
| 37 | +28. Find common elements in two lists |
| 38 | +29. Find difference of two lists |
| 39 | +30. Find intersection of two lists |
| 40 | +31. Find union of two lists |
| 41 | +32. Rotate list by n positions |
| 42 | +33. Find second largest element |
| 43 | +34. Find second smallest element |
| 44 | +35. Move zeros to end of list |
| 45 | + |
| 46 | +### Hard (36-50) |
| 47 | + |
| 48 | +36. Find majority element (> n/2 occurrences) |
| 49 | +37. Find missing number in sequence 1-n |
| 50 | +38. Find duplicate in array |
| 51 | +39. Find pair with given sum |
| 52 | +40. Find triplet with given sum |
| 53 | +41. Find maximum subarray sum (Kadane's) |
| 54 | +42. Find product of array except self |
| 55 | +43. Find leaders in array |
| 56 | +44. Find trapping rainwater |
| 57 | +45. Find maximum profit from stock prices |
| 58 | +46. Implement two stacks in one list |
| 59 | +47. Find equilibrium index |
| 60 | +48. Find pivot index |
| 61 | +49. Sort array of 0s, 1s, 2s (Dutch flag) |
| 62 | +50. Find kth largest element |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## Section 8: Tuples & Sets (40 exercises) |
| 67 | + |
| 68 | +### Tuples (1-20) |
| 69 | + |
| 70 | +1. Create empty tuple |
| 71 | +2. Create tuple with 5 elements |
| 72 | +3. Create tuple with single element |
| 73 | +4. Access tuple element by index |
| 74 | +5. Find length of tuple |
| 75 | +6. Concatenate two tuples |
| 76 | +7. Repeat tuple n times |
| 77 | +8. Find index of element in tuple |
| 78 | +9. Count occurrence of element |
| 79 | +10. Find maximum in tuple |
| 80 | +11. Find minimum in tuple |
| 81 | +12. Sum all elements in tuple |
| 82 | +13. Convert list to tuple |
| 83 | +14. Convert tuple to list |
| 84 | +15. Unpack tuple into variables |
| 85 | +16. Create nested tuple |
| 86 | +17. Access nested tuple elements |
| 87 | +18. Find hash of tuple |
| 88 | +19. Check if element exists in tuple |
| 89 | +20. Slice a tuple |
| 90 | + |
| 91 | +### Sets (21-40) |
| 92 | + |
| 93 | +21. Create empty set |
| 94 | +22. Create set with elements |
| 95 | +23. Add element to set |
| 96 | +24. Remove element from set |
| 97 | +25. Discard element from set |
| 98 | +26. Pop element from set |
| 99 | +27. Clear all elements from set |
| 100 | +28. Find length of set |
| 101 | +29. Check if element exists in set |
| 102 | +30. Find union of two sets |
| 103 | +31. Find intersection of two sets |
| 104 | +32. Find difference of two sets |
| 105 | +33. Find symmetric difference |
| 106 | +34. Check if set is subset |
| 107 | +35. Check if set is superset |
| 108 | +36. Check if sets are disjoint |
| 109 | +37. Add multiple elements to set |
| 110 | +38. Update set with another set |
| 111 | +39. Find set comprehension |
| 112 | +40. Remove duplicates from list using set |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## Section 9: Dictionaries (50 exercises) |
| 117 | + |
| 118 | +### Easy (1-18) |
| 119 | + |
| 120 | +1. Create empty dictionary |
| 121 | +2. Create dictionary with key-value pairs |
| 122 | +3. Access value by key |
| 123 | +4. Add new key-value pair |
| 124 | +5. Update value of existing key |
| 125 | +6. Remove key-value pair |
| 126 | +7. Find length of dictionary |
| 127 | +8. Check if key exists |
| 128 | +9. Get all keys |
| 129 | +10. Get all values |
| 130 | +11. Get all key-value pairs |
| 131 | +12. Get value with default |
| 132 | +13. Copy dictionary |
| 133 | +14. Clear dictionary |
| 134 | +15. Create dictionary from keys |
| 135 | +16. Create dictionary from values |
| 136 | +17. Merge two dictionaries |
| 137 | +18. Find key with maximum value |
| 138 | + |
| 139 | +### Medium (19-35) |
| 140 | + |
| 141 | +19. Find key with minimum value |
| 142 | +20. Sort dictionary by keys |
| 143 | +21. Sort dictionary by values |
| 144 | +22. Count frequency of elements using dict |
| 145 | +23. Invert dictionary (keys become values) |
| 146 | +24. Find common keys in two dicts |
| 147 | +25. Find difference of keys |
| 148 | +26. Group elements by key |
| 149 | +27. Filter dictionary by value |
| 150 | +28. Map dictionary values |
| 151 | +29. Create nested dictionary |
| 152 | +30. Access nested dictionary |
| 153 | +31. Flatten nested dictionary |
| 154 | +32. Convert two lists to dictionary |
| 155 | +33. Convert dictionary to list of tuples |
| 156 | +34. Find top 3 values |
| 157 | +35. Find top 3 keys |
| 158 | + |
| 159 | +### Hard (36-50) |
| 160 | + |
| 161 | +36. Implement LRU cache using dict |
| 162 | +37. Find anagrams grouping |
| 163 | +38. Find word frequency in text |
| 164 | +39. Implement phone book |
| 165 | +40. Implement inventory system |
| 166 | +41. Find pairs with given sum |
| 167 | +42. Find longest chain of pairs |
| 168 | +43. Implement trie using nested dicts |
| 169 | +44. Find shortest path in graph |
| 170 | +45. Count connected components |
| 171 | +46. Implement hash map |
| 172 | +47. Find majority element |
| 173 | +48. Find k most frequent elements |
| 174 | +49. Find minimum window substring |
| 175 | +50. Implement autocomplete system |
| 176 | + |
| 177 | +--- |
| 178 | + |
| 179 | +## Section 10: File Handling (40 exercises) |
| 180 | + |
| 181 | +### Easy (1-15) |
| 182 | + |
| 183 | +1. Create new text file |
| 184 | +2. Write text to file |
| 185 | +3. Read entire file content |
| 186 | +4. Read file line by line |
| 187 | +5. Read first n lines |
| 188 | +6. Read last n lines |
| 189 | +7. Append text to file |
| 190 | +8. Copy file content to another file |
| 191 | +9. Count lines in file |
| 192 | +10. Count words in file |
| 193 | +11. Count characters in file |
| 194 | +12. Find longest word in file |
| 195 | +13. Find shortest word in file |
| 196 | +14. Search for word in file |
| 197 | +15. Replace word in file |
| 198 | + |
| 199 | +### Medium (16-30) |
| 200 | + |
| 201 | +16. Count frequency of each word |
| 202 | +17. Remove duplicate lines |
| 203 | +18. Sort lines alphabetically |
| 204 | +19. Reverse content of file |
| 205 | +20. Merge two files |
| 206 | +21. Split file into n parts |
| 207 | +22. Find common words in two files |
| 208 | +23. Create log file parser |
| 209 | +24. Read CSV file |
| 210 | +25. Write to CSV file |
| 211 | +26. Read JSON file |
| 212 | +27. Write to JSON file |
| 213 | +28. Find file size |
| 214 | +29. Check if file exists |
| 215 | +30. Get file creation/modification time |
| 216 | + |
| 217 | +### Hard (31-40) |
| 218 | + |
| 219 | +31. Implement file compression |
| 220 | +32. Implement file encryption |
| 221 | +33. Create backup system |
| 222 | +34. Find duplicate files |
| 223 | +35. Search file in directory |
| 224 | +36. Batch rename files |
| 225 | +37. Organize files by extension |
| 226 | +38. Create file indexer |
| 227 | +39. Implement tail -f command |
| 228 | +40. Parse large file efficiently |
| 229 | + |
| 230 | +--- |
| 231 | + |
| 232 | +## Section 11: OOP (60 exercises) |
| 233 | + |
| 234 | +### Easy (1-20) |
| 235 | + |
| 236 | +1. Create simple class with attributes |
| 237 | +2. Create class with methods |
| 238 | +3. Create constructor __init__ |
| 239 | +4. Create __str__ method |
| 240 | +5. Create __repr__ method |
| 241 | +6. Create class with private attributes |
| 242 | +7. Create getter method |
| 243 | +8. Create setter method |
| 244 | +9. Create class variable |
| 245 | +10. Create instance variable |
| 246 | +11. Create static method |
| 247 | +12. Create class method |
| 248 | +13. Create property decorator |
| 249 | +14. Create setter decorator |
| 250 | +15. Create deleter decorator |
| 251 | +16. Inherit from parent class |
| 252 | +17. Override parent method |
| 253 | +18. Use super() function |
| 254 | +19. Check instance type |
| 255 | +20. Check class inheritance |
| 256 | + |
| 257 | +### Medium (21-40) |
| 258 | + |
| 259 | +21. Implement multiple inheritance |
| 260 | +22. Implement multilevel inheritance |
| 261 | +23. Implement hierarchical inheritance |
| 262 | +24. Implement hybrid inheritance |
| 263 | +25. Create abstract base class |
| 264 | +26. Implement interface |
| 265 | +27. Implement operator overloading (+) |
| 266 | +28. Implement operator overloading (-) |
| 267 | +29. Implement operator overloading (==) |
| 268 | +30. Implement operator overloading (<) |
| 269 | +31. Implement __len__ method |
| 270 | +32. Implement __iter__ method |
| 271 | +33. Implement __next__ method |
| 272 | +34. Implement __call__ method |
| 273 | +35. Implement __getitem__ method |
| 274 | +36. Implement __setitem__ method |
| 275 | +37. Implement __delitem__ method |
| 276 | +38. Implement context manager |
| 277 | +39. Implement descriptor |
| 278 | +40. Implement weak reference |
| 279 | + |
| 280 | +### Hard (41-60) |
| 281 | + |
| 282 | +41. Implement singleton pattern |
| 283 | +42. Implement factory pattern |
| 284 | +43. Implement observer pattern |
| 285 | +44. Implement strategy pattern |
| 286 | +45. Implement decorator pattern |
| 287 | +46. Implement adapter pattern |
| 288 | +47. Implement facade pattern |
| 289 | +48. Implement proxy pattern |
| 290 | +49. Implement command pattern |
| 291 | +50. Implement state pattern |
| 292 | +51. Implement template method pattern |
| 293 | +52. Implement iterator pattern |
| 294 | +53. Implement composite pattern |
| 295 | +54. Implement builder pattern |
| 296 | +55. Implement prototype pattern |
| 297 | +56. Implement flyweight pattern |
| 298 | +57. Implement chain of responsibility |
| 299 | +58. Implement mediator pattern |
| 300 | +59. Implement memento pattern |
| 301 | +60. Implement visitor pattern |
| 302 | + |
| 303 | +--- |
| 304 | + |
| 305 | +## Section 12: Error Handling (30 exercises) |
| 306 | + |
| 307 | +### Easy (1-12) |
| 308 | + |
| 309 | +1. Handle ZeroDivisionError |
| 310 | +2. Handle ValueError |
| 311 | +3. Handle TypeError |
| 312 | +4. Handle IndexError |
| 313 | +5. Handle KeyError |
| 314 | +6. Handle FileNotFoundError |
| 315 | +7. Handle multiple exceptions |
| 316 | +8. Use else clause |
| 317 | +9. Use finally clause |
| 318 | +10. Raise exception manually |
| 319 | +11. Create custom exception |
| 320 | +12. Chain exceptions |
| 321 | + |
| 322 | +### Medium (13-22) |
| 323 | + |
| 324 | +13. Validate email with exception |
| 325 | +14. Validate phone with exception |
| 326 | +15. Validate age with exception |
| 327 | +16. Create validation exception hierarchy |
| 328 | +17. Handle file operation errors |
| 329 | +18. Handle database errors |
| 330 | +19. Handle API request errors |
| 331 | +20. Handle JSON parsing errors |
| 332 | +21. Handle network timeout |
| 333 | +22. Retry on failure |
| 334 | + |
| 335 | +### Hard (23-30) |
| 336 | + |
| 337 | +23. Implement transaction rollback |
| 338 | +24. Create error logging system |
| 339 | +25. Implement circuit breaker |
| 340 | +26. Create custom exception framework |
| 341 | +27. Handle async errors |
| 342 | +28. Implement error recovery |
| 343 | +29. Create fault-tolerant system |
| 344 | +30. Implement graceful degradation |
| 345 | + |
| 346 | +--- |
| 347 | + |
| 348 | +## Section 13: Modules & Packages (30 exercises) |
| 349 | + |
| 350 | +### Easy (1-12) |
| 351 | + |
| 352 | +1. Create simple module |
| 353 | +2. Import module |
| 354 | +3. Import specific function |
| 355 | +4. Import with alias |
| 356 | +5. Import all from module |
| 357 | +6. Create package with __init__.py |
| 358 | +7. Import from package |
| 359 | +8. Use relative import |
| 360 | +9. Use absolute import |
| 361 | +10. Create submodule |
| 362 | +11. Use if __name__ == "__main__" |
| 363 | +12. Create module documentation |
| 364 | + |
| 365 | +### Medium (13-22) |
| 366 | + |
| 367 | +13. Create utility module |
| 368 | +14. Create math module |
| 369 | +15. Create string module |
| 370 | +16. Create file operations module |
| 371 | +17. Create date/time module |
| 372 | +18. Use built-in random module |
| 373 | +19. Use built-in math module |
| 374 | +20. Use built-in datetime module |
| 375 | +21. Use built-in collections module |
| 376 | +22. Use built-in itertools module |
| 377 | + |
| 378 | +### Hard (23-30) |
| 379 | + |
| 380 | +23. Create pip-installable package |
| 381 | +24. Add package to PyPI |
| 382 | +25. Create module with C extension |
| 383 | +26. Use importlib for dynamic import |
| 384 | +27. Create module loader |
| 385 | +28. Implement plugin system |
| 386 | +29. Create namespace package |
| 387 | +30. Implement module versioning |
| 388 | + |
| 389 | +--- |
| 390 | + |
| 391 | +*Continued in Part 3...* |
0 commit comments