Python Collections

KELAS DATA SCRAPING




Kampus Remote Worker Indonesia | 2024

Data Scraping | rianaditro

Lists vs Dictionaries

When working on data scraping tasks, it's essential to be familiar with core Python data structures like lists, and dictionaries, as they are key to processing and organizing the scraped data efficiently.

an_empty_list = []
an_empty_dictionary = dict()
Data Scraping | rianaditro

Common List Operations

1. append()

data = []
data.append("Product A")
data.append("Product B")
print(data)  # Output: ['Product A', 'Product B']

2. extend()

data1 = ["Product A", "Product B"]
data2 = ["Product C", "Product D"]
data1.extend(data2)
print(data1)  # Output: ['Product A', 'Product B', 'Product C', 'Product D']
Data Scraping | rianaditro

Common Dictionary Operations

1. get()

data = {"name": "Laptop", "price": 999.99}
product_name = data.get("name", "Unknown")
product_rating = data.get("rating", "No rating")  # Key not present, returns default
print(product_name)  # Output: Laptop
print(product_rating)  # Output: No rating

2. keys()

data = {"name": "Laptop", "price": 999.99}
keys = data.keys()
print(keys)  # Output: dict_keys(['name', 'price'])
Data Scraping | rianaditro

3. values()

data = {"name": "Laptop", "price": 999.99}
values = data.values()
print(values)  # Output: dict_values(['Laptop', 999.99])

4. items()

data = {"name": "Laptop", "price": 999.99}
for key, value in data.items():
    print(f"{key}: {value}")
# Output:
# name: Laptop
# price: 999.99
Data Scraping | rianaditro

Class Activity

Complete these List Exercise and Dictionary Exercise!

Data Scraping | rianaditro

Learn More

Join us on this self-study journey! Click the link below to get started.

Data Scraping | rianaditro

Discover Advanced Topic

Master this advanced topic and supercharge your skills.

Data Scraping | rianaditro

Homework Assignment

Complete this Data Structure Challenges to enhance your understanding.

Data Scraping | rianaditro




Thank you

Any Question?




Kampus Remote Worker Indonesia | 2024

Data Scraping | rianaditro

<br>

<br>