Module 3: Technical Preparation: Strings and Arrays

Overview

Module 3 focuses on working with strings and arrays (lists) in Python. You'll learn how to manipulate text data using string methods, implement for-loops to iterate through sequences, and master array operations with while-loops. These skills are essential for solving coding challenges and performing well on the General Code Assessment (GCA).

Core Competencies: Strings and For-Loops

String Basics

This section covers the fundamentals of working with strings, including:

  • String creation and initialization
  • Accessing characters using indexing
  • String immutability and its implications
  • Common string methods and properties

String Case and Concatenation

Learn about manipulating the case of strings and joining them together:

  • Converting between uppercase and lowercase
  • Checking case with isupper() and islower()
  • String concatenation using the + operator
  • Joining multiple strings efficiently

Formatted Strings

Master the art of string formatting:

  • Using f-strings in Python 3.6+
  • The format() method for string templating
  • Formatting numbers and dates
  • Aligning and padding text output

For Loop Refresher

Review the fundamentals of for-loops:

  • Basic for-loop syntax
  • Looping through sequences
  • Using the range() function
  • Break and continue statements

For Loop String Demo

See for-loops in action with strings:

  • Iterating through characters in a string
  • Building new strings character by character
  • String transformation techniques
  • Practical string manipulation examples

Core Competencies: Arrays and While-Loops

Note: While these videos use the term "array," Python officially calls these data structures "lists." The concepts are essentially the same, but you'll see list in Python documentation and examples. Both terms are commonly used in programming discussions.

Array Length

Understand how to work with array sizes:

  • Using the len() function
  • Empty arrays and their properties
  • Applications of array length in algorithms

Array Access

Learn how to access array elements:

  • Indexing syntax and zero-based indexing
  • Negative indexing for accessing elements from the end
  • Slicing to get sub-arrays
  • Handling index out of range errors

Array Modification Operations

Discover ways to modify arrays:

  • Changing elements using indexing
  • Replacing sections with slicing
  • In-place operations vs. creating new arrays

Array Push (Append)

Learn to add elements to arrays:

  • Using the append() method
  • Inserting elements with insert()
  • Extending arrays with extend()
  • Performance considerations for different operations

Array Delete

Master removing elements from arrays:

  • Removing by value with remove()
  • Removing by index with pop()
  • Deleting slices with the del statement
  • Clearing arrays completely

Array Filtering

Learn to filter arrays based on conditions:

  • Using list comprehensions for filtering
  • The filter() function
  • Building filtered arrays with loops
  • Combining filtering with other operations

Guided Project

In the guided project, you'll practice using LeetCode to solve programming challenges that focus on strings, arrays, and loops. You'll apply your knowledge of text processing, data transformation, and implement algorithms that manipulate collections of data.

Project Resources

Recommended LeetCode Problems

Note: For all problems, you can select Python as your programming language using the dropdown menu in the LeetCode code editor.

Practice Activities

To reinforce your understanding of the concepts covered in this module, complete the following activities:

  • Choose and solve at least 5 problems from the recommended list above
  • For each problem:
    • First try to solve it without looking at hints
    • If you get stuck, use the Hints feature (available on most problems)
    • Consider reviewing the Discussion section to see how others approached the problem
  • Practice applying different string methods in your solutions
  • Try implementing both for-loop and while-loop based approaches where possible

Additional Resources