Data Structures – 1D Lists

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Lists Introduction to Computing Science and Programming I.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
Starter – Homework What were our findings?. Computer Science Constants_variables and data types 2.
Lists in Python.
Python November 28, Unit 9+. Local and Global Variables There are two main types of variables in Python: local and global –The explanation of local and.
Database A database program is a piece of software to organize and sort information. It creates an electronic list of information that can be sorted very.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Built-in Data Structures in Python An Introduction.
Lists. The list is a most versatile datatype available in Python which can be written as a list of comma-separated values (items) between square brackets.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
CPS120: Introduction to Computer Science Sorting.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
CPS120: Introduction to Computer Science Sorting.
String and Lists Dr. José M. Reyes Álamo.
Data types: Complex types (List)
Python - Lists.
Containers and Lists CIS 40 – Introduction to Programming in Python
JavaScript: Functions.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Python I/O.
File Handling Programming Guides.
Bryan Burlingame 03 October 2018
Creation, Traversal, Insertion and Removal
LESSON 13 – INTRO TO ARRAYS
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
CS190/295 Programming in Python for Life Sciences: Lecture 6
6. Lists Let's Learn Python and Pygame
Coding Concepts (Data Structures)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
ARRAYS 1 GCSE COMPUTER SCIENCE.
String and Lists Dr. José M. Reyes Álamo.
Remembering lists of values lists
Just Basic Lessons Mr. Kalmes.
Topics Sequences Introduction to Lists List Slicing
For Loops (Iteration 1) Programming Guides.
Programming Control Structures with JavaScript Part 2
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Python Lists.
JavaScript: Arrays.
For loops Taken from notes by Dr. Neil Moore
Topics Introduction to File Input and Output
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Programming with Python
To understand what arrays are and how to use them
Fundaments of Game Design
Topics Sequences Introduction to Lists List Slicing
Python Review
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Just Basic Lessons Mr. Kalmes.
Arrays & Loops.
Arrays & Loops.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Arrays.
Python List.
Tuple.
Introduction to Computer Science
Presentation transcript:

Data Structures – 1D Lists Programming Guides

Data Structures – 1D Lists Programming languages don’t just provide the ability to store single pieces of data in variables … … they also provide another kind of data type which can hold a number of data items This type of data structure is known as a LIST

Data Structures – 1D Lists Lists can be thought of as a table of data: In Python you could create the above list using the following code: Index 1 2 3 4 List Item “Train” “Car” “Foot” “Bus” “Taxi”

Data Structures – 1D Lists Programmers count from ZERO! The first item in a list is therefore at position ‘0’. Don’t forget this!!!

Data Structures – 1D Lists Notice that we assign the data to the variable in the usual way (‘=’ sign). But for a list we also use square brackets [ ] and commas to separate our data items.

Data Structures – 1D Lists Once we have created our list there are lots of things we can do with them. We can: Print lists Reverse the order of the list Sort the list into alphabetical order or numerical order (if the data is number) Append the list (add items on to the end) Remove items from the list Find the position of certain items on our list Count how many times a particular item appears in the list Insert items into a particular position of the list “Pop” an item out of the list.

Data Structures – 1D Lists Printing the contents of a list:

Data Structures – 1D Lists Reversing the contents of a list:

Data Structures – 1D Lists Sorting the contents of a list:

Data Structures – 1D Lists Appending to the contents of a list (adding items onto the end of a list):

Data Structures – 1D Lists Removing an item from a list:

Data Structures – 1D Lists Locating the index (position) of an item in a list:

Data Structures – 1D Lists Counting specific items in a list:

Data Structures – 1D Lists Inserting an item into a list at a particular location (index):

Data Structures – 1D Lists Popping items out of a list:

Data Structures – 1D Lists Often, a program will use a list to record user inputs. In Python we need to create an empty list and then use the append function to add new items into the list. We could do this in a loop to be more efficient.