Intro to Computer Science CS1510 Dr. Sarah Diesburg

Slides:



Advertisements
Similar presentations
JaySummet IPRE Python Review 2. 2 Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing.
Advertisements

October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
Chapter 7 Lists and Tuples. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. Data Structures.
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.
Lists and Tuples Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CIT 590 Intro to Programming Lecture 5 – completing lists.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Tuples and Dictionaries Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
COSC 1306—COMPUTER SCIENCE AND PROGRAMMING PYTHON TUPLES, SETS AND DICTIONARIES Jehan-François Pâris
Dictionaries Intro to Computer Science CS 1510 Dr. Sarah Diesburg.
Python Data Structures By Greg Felber. Lists An ordered group of items Does not need to be the same type – Could put numbers, strings or donkeys in the.
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.
String and Lists Dr. José M. Reyes Álamo.
Tuples and Lists.
Chapter 4 Strings & Tuples
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 8 Namespaces and Memory Realities
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
Introduction to Strings
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
Lists – Indexing and Sorting
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
Bryan Burlingame Halloween 2018
Types, Truth, and Expressions (Part 2)
String Encodings and Penny Math
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Types, Truth, and Expressions (Part 2)
CS190/295 Programming in Python for Life Sciences: Lecture 6
6. Lists Let's Learn Python and Pygame
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
4. sequence data type Rocky K. C. Chang 16 September 2018
Chapter 8 Namespaces and Memory Realities
Thinking about Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
String and Lists Dr. José M. Reyes Álamo.
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lists – Indexing and Sorting
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CS1110 Today: collections.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 8 Namespaces and Memory Realities
Bryan Burlingame Halloween 2018
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Python Review
Lists – Indexing and Sorting
Copyright (c) 2017 by Dr. E. Horvath
String Encodings and Penny Math
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Types, Truth, and Expressions
CSE 231 Lab 6.
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Presentation transcript:

Intro to Computer Science CS1510 Dr. Sarah Diesburg Lists and Tuples Intro to Computer Science CS1510 Dr. Sarah Diesburg

Tuples Tuples are easy: they are simply immutable lists. They are designated with a comma: Not the parenthesis! myTuple = (1,’a’,3.14,True) newTuple = (,) #Empty tuple anotherTuple = 2,3 #Tuple without parenthesis

The Question is, Why? The real question is, why have an immutable list, a tuple, as a separate type? An immutable list gives you a data structure with some integrity, some permanency, if you will. You know you cannot accidentally change one.

Lists and Tuples Everything that works with a list works with a tuple except methods that modify the list/tuple. Thus indexing, slicing, len, print all work as expected. However, none of the mutable methods work: append, extend, remove.

Anagram Example with Tuples Let’s make an anagram program and look at how we can use it with lists and tuples