Create Lists Practice Problem
This data science coding problem helps you practice Lists & Basic Data Structures, create lists, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Lists & Basic Data Structures.
- Problem ID: 70
- Problem key: 70-create-lists
- URL: https://datacrack.app/solve/70-create-lists
- Difficulty: easy
- Topic: Lists & Basic Data Structures
- Module: Python Fundamentals
Problem Statement
# 🧩 Create Lists
---
### 🎯 Goal
Lists are the most fundamental data structure in Python. Before you can manipulate data, you need to know how to **create** lists in different ways — from literal values, from ranges, and from mixed types.
---
### 🔍 What You Need to Know
| Method | Example | Result |
|:-------|:--------|:-------|
| Literal | `[1, 2, 3]` | A list of integers |
| Empty list | `[]` or `list()` | An empty list |
| From `range()` | `list(range(5))` | `[0, 1, 2, 3, 4]` |
| Mixed types | `[1, "hi", 3.14]` | A list with int, str, float |
---
### 💻 Task
Implement `create_list(elements)` that takes a sequence of elements and returns them as a Python list.
---
### 📥 Input
- `elements`: a sequence of values (could be numbers, strings, or mixed types)
### 📤 Output
- A Python `list` containing those elements in the same order
---
### 🧩 Starter Code
```python
def create_list(elements):
"""
Return the given elements as a Python list.
Args:
elements: A sequence of values
Returns:
list: A list containing the elements
"""
# 🧠 TODO: Convert the input into a list and return it
pass
```
---
### 💡 Example
```python
create_list([1, 2, 3, 4, 5])
# Expected: [1, 2, 3, 4, 5]
create_list(["apple", "banana", "cherry"])
# Expected: ["apple", "banana", "cherry"]
```
---
### 🔑 Key Concepts
- Square brackets `[]` define a list literal
- `list()` can convert other iterables into a list
- Python lists can hold **mixed types** — ints, strings, floats, booleans all in one list
- An empty list `[]` is valid and commonly used as a starting pointStarter Code
def create_list(elements):
"""
Return the given elements as a Python list.
Args:
elements: A sequence of values
Returns:
list: A list containing the elements
"""
# 🧠 TODO: Convert the input into a list and return it
pass