Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Lists and Dictionaries for Chemical Data | Python Foundations for Chemists
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Chemists

bookLists and Dictionaries for Chemical Data

Handling chemical data efficiently is essential in laboratory work, where you often need to organize sets of measurements or sample properties. In Python, you can use lists to store multiple values of the same kind, such as a series of pH readings from a titration experiment. This approach allows you to keep related data together, making it easier to analyze and process.

Note
Definition

A list is an ordered collection of items, useful for storing multiple measurements such as pH readings or absorbance values from an experiment.

123
# List of pH values recorded during a titration experiment ph_readings = [2.3, 2.8, 3.1, 3.6, 4.0, 4.5, 5.1, 5.8, 6.3, 7.0] print("pH readings:", ph_readings)
copy

While lists are ideal for storing sequences of similar measurements, sometimes you need to associate specific data—like concentrations—with particular samples. In these cases, a dictionary is a better fit. Dictionaries let you map a unique key (such as a sample name) to a value (such as its concentration), making it easy to look up or update information based on the sample identifier.

Note
Definition

A dictionary is a collection of key-value pairs, ideal for mapping sample names to their properties, like concentrations or volumes. Both structures help organize and manage experimental data efficiently.

1234567
# Dictionary mapping sample names to their concentrations (in mol/L) concentrations = { "Sample A": 0.10, "Sample B": 0.25, "Sample C": 0.50 } print("Concentrations:", concentrations)
copy

To get the most out of lists and dictionaries, you need to know how to access and update their values. For a list, you use an index number: ph_readings[0] gives you the first pH value. You can change a value by assigning a new one to an index, like ph_readings[2] = 3.2.

12345678910
# List of pH values recorded during a titration experiment ph_readings = [2.3, 2.8, 3.1, 3.6, 4.0, 4.5, 5.1, 5.8, 6.3, 7.0] # Access the first pH value first_ph = ph_readings[0] print("First pH value:", first_ph) # Update the third value (index 2) to 3.2 ph_readings[2] = 3.2 print("Updated pH readings:", ph_readings)
copy

For a dictionary, you access a value with its key: concentrations["Sample A"] returns the concentration of "Sample A". You can update it with a similar assignment: concentrations["Sample A"] = 0.12. This flexibility lets you keep your experimental data organized and up-to-date as you work.

1234567891011121314
# Dictionary mapping sample names to their concentrations (in mol/L) concentrations = { "Sample A": 0.10, "Sample B": 0.25, "Sample C": 0.50 } # Access the concentration of 'Sample A' sample_a_conc = concentrations["Sample A"] print("Concentration of Sample A:", sample_a_conc) # Update the concentration of 'Sample A' to 0.12 concentrations["Sample A"] = 0.12 print("Updated concentrations:", concentrations)
copy

1. What Python structure would you use to store the absorbance values for several samples?

2. How do you access the concentration of 'Sample A' in a dictionary called concentrations?

3. Why might a dictionary be more useful than a list for storing sample data?

question mark

What Python structure would you use to store the absorbance values for several samples?

Select the correct answer

question mark

How do you access the concentration of 'Sample A' in a dictionary called concentrations?

Select the correct answer

question mark

Why might a dictionary be more useful than a list for storing sample data?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Can you explain more about when to use lists versus dictionaries?

How can I add new values to a list or dictionary?

What are some common mistakes to avoid when working with lists and dictionaries?

bookLists and Dictionaries for Chemical Data

Veeg om het menu te tonen

Handling chemical data efficiently is essential in laboratory work, where you often need to organize sets of measurements or sample properties. In Python, you can use lists to store multiple values of the same kind, such as a series of pH readings from a titration experiment. This approach allows you to keep related data together, making it easier to analyze and process.

Note
Definition

A list is an ordered collection of items, useful for storing multiple measurements such as pH readings or absorbance values from an experiment.

123
# List of pH values recorded during a titration experiment ph_readings = [2.3, 2.8, 3.1, 3.6, 4.0, 4.5, 5.1, 5.8, 6.3, 7.0] print("pH readings:", ph_readings)
copy

While lists are ideal for storing sequences of similar measurements, sometimes you need to associate specific data—like concentrations—with particular samples. In these cases, a dictionary is a better fit. Dictionaries let you map a unique key (such as a sample name) to a value (such as its concentration), making it easy to look up or update information based on the sample identifier.

Note
Definition

A dictionary is a collection of key-value pairs, ideal for mapping sample names to their properties, like concentrations or volumes. Both structures help organize and manage experimental data efficiently.

1234567
# Dictionary mapping sample names to their concentrations (in mol/L) concentrations = { "Sample A": 0.10, "Sample B": 0.25, "Sample C": 0.50 } print("Concentrations:", concentrations)
copy

To get the most out of lists and dictionaries, you need to know how to access and update their values. For a list, you use an index number: ph_readings[0] gives you the first pH value. You can change a value by assigning a new one to an index, like ph_readings[2] = 3.2.

12345678910
# List of pH values recorded during a titration experiment ph_readings = [2.3, 2.8, 3.1, 3.6, 4.0, 4.5, 5.1, 5.8, 6.3, 7.0] # Access the first pH value first_ph = ph_readings[0] print("First pH value:", first_ph) # Update the third value (index 2) to 3.2 ph_readings[2] = 3.2 print("Updated pH readings:", ph_readings)
copy

For a dictionary, you access a value with its key: concentrations["Sample A"] returns the concentration of "Sample A". You can update it with a similar assignment: concentrations["Sample A"] = 0.12. This flexibility lets you keep your experimental data organized and up-to-date as you work.

1234567891011121314
# Dictionary mapping sample names to their concentrations (in mol/L) concentrations = { "Sample A": 0.10, "Sample B": 0.25, "Sample C": 0.50 } # Access the concentration of 'Sample A' sample_a_conc = concentrations["Sample A"] print("Concentration of Sample A:", sample_a_conc) # Update the concentration of 'Sample A' to 0.12 concentrations["Sample A"] = 0.12 print("Updated concentrations:", concentrations)
copy

1. What Python structure would you use to store the absorbance values for several samples?

2. How do you access the concentration of 'Sample A' in a dictionary called concentrations?

3. Why might a dictionary be more useful than a list for storing sample data?

question mark

What Python structure would you use to store the absorbance values for several samples?

Select the correct answer

question mark

How do you access the concentration of 'Sample A' in a dictionary called concentrations?

Select the correct answer

question mark

Why might a dictionary be more useful than a list for storing sample data?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4
some-alt