Python Collections

In this project, you'll dive into Python tuple manipulation, mastering skills in creating, accessing, modifying, and analyzing tuples through practical challenges. Using a real-world student dataset, you'll explore sorting, slicing, filtering, and concatenating, gaining hands-on experience that enhances your understanding of tuples in Python. Perfect for those looking to sharpen their Python skills in an engaging, practical way.
Project Created by

## Project Activities

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

input

### Total number of grade `A` students

Loop through the `students` tuple and find the total number of students with grade `A`.

codevalidated

### Matching Grades and Student Counts

Construct a nested tuple named `grade_count` that stores pairs of grades and their corresponding counts of students with that grade.

``````grade_count = (
('A', 23),
('B', 20),
('C', 17),
('D', 15),
('E', 25),
('F', 20)
)
``````

Note that this is an illustrative example, and your actual solution will follow a similar pattern.

codevalidated

### Create a new tuple containing the names of students with grades 'F'

Create a new tuple named `failed_students` sorted alphabetically that contains the names of students with grades `F`.

codevalidated

### Sort the students tuple based on student names in ascending order.

Sort the `students` tuple based on student names in ascending order and store the result in a new tuple named `sorted_students`.

If the tuple is like below:

``````students = (
(1, 2),
('Joseph Mendoza', 'Carlos Green'),
('1818 Guzman Court Suite 712\nEast Carolyntown, IN 32206', '80276 Paul Trace\nSouth Chad, GA 46047'),
('A', 'B')
)
``````

Then the sorted tuple should look like below:

``````sorted_students = (
(2, 1),
('Carlos Green', 'Joseph Mendoza'),
('80276 Paul Trace\nSouth Chad, GA 46047',
'1818 Guzman Court Suite 712\nEast Carolyntown, IN 32206'),
('B', 'A')
)
``````
codevalidated

### Split the students tuple into two separate tuples containing the first and last 50 students.

Split the `students` tuple into two separate tuples containing the first and last 50 students, respectively. Store the first 50 students in a tuple named `first_half` and the last 50 students in a tuple named `second_half`.

input

### Find the address of the student with the name 'Stephanie Harris' in the students tuple.

Find the address of the student with the name 'Stephanie Harris' in the `students` tuple.

Enter the address below input box as string.

If there are multiple students with same name input the address of the students who occur first.

multiplechoice

### Check if the grade `E` exists in the `students` tuple

Check if the grade `E` exists in the `students` tuple.

input

### Find the index of the first occurrence of grade 'B' in the students tuple.

Find the index of the first occurrence of grade `B` in the `students` tuple.

input

### Find the index of the last occurrence of grade 'C' in the students tuple.

Find the index of the last occurrence of grade `C` in the `students` tuple.

codevalidated

### Create a new tuple containing the names of students with names longer than 15 characters.

Create a new tuple named `long_names` that contains the names of students with names longer than 15 characters.

codevalidated

### Remove the student with the name 'Daniel Golden' from the students tuple.

Remove the student with the name 'Daniel Golden' from the `students` tuple.

If there are multiple students with name `Daniel` then remove the first occurence.

If you not able to pass the activity even after correct solution then try again reading `students` data.

The tuples are `immutable`, meaning that even though we're updating them, we're creating new tuples to take the place of the old ones.

input

### Name the first student who has grade `D`

Name the first student who has grade `D`.

Enter the name below input box as string.

codevalidated

### Replace the grade of the student named 'Kevin Mccormick DVM' with 'B' in the students tuple.

Replace the grade of the student named 'Kevin Mccormick DVM' with 'B' in the `students` tuple.

If there are multiple students with name `Kevin Mccormick DVM` then replace the grade of the first occurence.

Note that, tuples are `immutable`, we need to create a new tuples to take the place of the old ones.

codevalidated

I think you noticed there are no students with grade `E`, so let's add 6 students with grade `E` in the `students` tuple. Below are the details of six students:

``````student_ids = (100, 101, 102, 103, 104, 105)
student_names = ('John Doe', 'Twinkle Khanna', 'Jackson', 'Sunny Deol', 'Narendra Modi', 'Rahul Gandhi')
"123, Gali No. 4, Sarai Rohilla, New Delhi, Delhi, 110007",
"456, MG Road, Shivaji Nagar, Bangalore, Karnataka, 560001",
"789, Park Street, Park Circus, Kolkata, West Bengal, 700017",
"987, Jubilee Hills, Banjara Hills, Hyderabad, Telangana, 500033",
"321, MG Road, Civil Lines, Jaipur, Rajasthan, 302001"
)
student_grades = ('E', 'E', 'E', 'E', 'E', 'E')
``````

Add these students detail at the end of the tuple.

codevalidated

### Store Details in a Separate Variable

Store all the student ids in a variable named `ids`, names in `names`, address in `address`, and grades in `grades`. All these variables are of type tuple.

Make sure to not change the order of details of students.

Project Created by

#### Anurag Verma

What's up, friends! 👋 I'm a computer science student about to finish my last year of college. 🎓 I LOVE writing code! ❤️ It makes me so happy! 😄 Whether I'm goofing in notebooks 📓 or coding in Python 🐍, writing programs is a blast! 💥

What's up, friends! 👋 I'm a computer science student about to finish my last year of college. 🎓 I LOVE writing code! ❤️ It makes me so happy! 😄 Whether I'm goofing in notebooks 📓 or coding in Python 🐍, writing programs is a blast! 💥

This project is part of

## Python Collections

Explore other projects