23 Things They Don't Tell You About Capitalism

Data Structures Overview

  • Data Structure: A combination of several data values organized in a unit to be accessed and manipulated.

Types of Data Structures

  • String: A sequence of characters, acts as a data structure for text.
  • List: A sequence of data values (items) that can be of any type. Ordered by position with indices starting from 0.
    • Examples of Lists:
    • Shopping list
    • To-do list
    • Roster for a team
    • Guest list
    • Recipe instructions
    • Text document lines
    • Phone book names

List Characteristics

  • Each item in a list has a unique index.
  • Operations for lists include:
    • Access: L[index]
    • Slice: L[start:end] returns a sublist.
    • Concatenation: L1 + L2 combines two lists.
    • Print: print(L) displays the list.
    • Length: len(L) gives the number of elements.

List Literals and Creation

  • A list literal in Python is denoted by square brackets (e.g., list = [1951, 1969, 1984]).
  • Empty list: []
  • Lists can contain other lists (nested lists). Example: [[5, 9], [541, 78]].

List Methods

  • Insertion:

    • list.insert(index, value) adds a value at a specified index.
    • list.append(value) adds a value to the end.
    • list.extend(other_list) appends elements from another list.
  • Removal:

    • list.pop(index) removes the value at a specified index.
    • list.pop() removes the last element.

Modifications to Lists

  • Lists are mutable; elements can be replaced, inserted, or removed.
  • Example:
    • Replacing:
      example = [1, 2, 3, 4] example[3] = 0 # Result: [1, 2, 3, 0]

Searching and Sorting Lists

  • Searching for an element can be done using the in operator.
  • Sorting: Use list.sort(), which arranges elements in ascending order.

Dictionaries

  • Dictionaries: Organize data by association (not by position).
  • Example: `{