List1 = ["gold", "gems ", "diamonds "] list2 = [“rubies", “emeralds ", “opals"] list3 = list1 + list2 print(list3) list1 +=list2 print(list1)

Slides:



Advertisements
Similar presentations
Python Mini-Course University of Oklahoma Department of Psychology
Advertisements

Lists Ruth Anderson CSE 140 University of Washington 1.
Course A201: Introduction to Programming 10/28/2010.
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
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.
Guide to Programming with Python
Lists/Tuples. Example Write a program to keep track of all students’ scores on exam 1. Need a list of everyone’s score Use 14 doubles What about next.
Lists/Tuples. Example Write a program to keep track of all students’ scores on exam 1. Need a list of everyone’s score Use 14 doubles What about next.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
2/28/2008. >>> Overview Arrays in Python – a.k.a. Lists Ranges are Lists Strings vs. Lists Tuples vs. Lists Map-Reduce Lambda Review: Printing to a file.
Data Structures Akshay Singh.  Lists in python can contain any data type  Declaring a list:  a = [‘random’,’variable’, 1, 2]
October 17, 2005ICP: Chapter 5: Lists and Dictionaries 1 Introduction to Computer Programming Chapter 5: Lists and Dictionaries Michael Scherger Department.
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.
Hossain Shahriar Announcement and reminder! Tentative date for final exam need to be fixed! Topics to be covered in this lecture(s)
10. Python - Lists The list is a most versatile datatype available in Python, which can be written as a list of comma-separated values (items) between.
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.
Lecture 19 - More on Lists, Slicing Lists, List Functions COMPSCI 101 Principles of Programming.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Daniel Jung. Types of Data Structures  Lists Stacks Queues  Tuples  Sets  Dictionaries.
Lists CS303E: Elements of Computers and Programming.
CPSC 217 T03 Week XII Part #1: Dictionary Hubert (Sathaporn) Hu.
Largest of x random numbers def find_largest(x,y): largest = 0; count = 0; while count < x: rnum = randrange(0,y) if rnum > largest: largest = rnum count.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 10 Lists 1.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Guide to Programming with Python Chapter Five Lists and dictionaries (data structure); The Hangman Game.
COP 2510 Chapter 6 - Functions. Random function (randint) #import the desired function import random #integer random number in the range of 1 through.
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.
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.
Python Files and Lists. Files  Chapter 9 actually introduces you to opening up files for reading  Chapter 14 has more on file I/O  Python can read.
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.
LISTS: A NEW TYPE! We've got: ints floats booleans strings and now… (drum roll) LISTS! sets of a thing (e.g., sets of ints)
11 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Python For Kids – Week 2 Subtitle. Variables  A variable is a container in which a data value can be stored within the computer’s memory  The data can.
String and Lists Dr. José M. Reyes Álamo.
CSc 110, Autumn 2016 Lecture 36: searching.
Gems, Precious Metals, and Jewelry
Data types: Complex types (List)
Starter You have been asked to write a program to store the names of everybody in a class. Assuming there are 20 pupils in the class, how would you do.
Embedded Software Development with Python and the Raspberry Pi
More on Lists.
From Think Python How to Think Like a Computer Scientist
Chapter 10 Lists.
Lists Part 1 Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Lists Part 1 Taken from notes by Dr. Neil Moore
Creation, Traversal, Insertion and Removal
Guide to Programming with Python
Perl Variables: Hash Web Programming.
Chapter 10 Lists.
6. Lists Let's Learn Python and Pygame
8 – Lists and tuples John R. Woodward.
Data Structures – 1D Lists
Python Data Structures
CS 1111 Introduction to Programming Fall 2018
String and Lists Dr. José M. Reyes Álamo.
Chapter 5: Lists and Dictionaries
Remembering lists of values lists
Topics Sequences Introduction to Lists List Slicing
Lists Part 1 Taken from notes by Dr. Neil Moore
CS 1111 Introduction to Programming Spring 2019
15-110: Principles of Computing
CIT 383: Administrative Scripting
Introduction to Programming with Python
Topics Sequences Introduction to Lists List Slicing
Lists: a new type! LISTS! sets of a thing (e.g., sets of ints)
COMPUTER SCIENCE PRESENTATION.
RANDOM NUMBERS SET # 1:
Python List.
Introduction to PYTHON
Presentation transcript:

list1 = ["gold", "gems ", "diamonds "] list2 = [“rubies", “emeralds ", “opals"] list3 = list1 + list2 print(list3) list1 +=list2 print(list1)

listofstuff = [“ant", “bear", “cat", “dog“,”elephant”] # assign by index listofstuff[0] = “aardvark" print(listofstuff) # assign by slice listofstuff[3:5] = [“dolphin"] print(listofstuff) # delete an element del listofstuff[2] print(listofstuff) # delete a slice del listofstuff[:2] print(listofstuff)

scores = [] #add a score newscore = 3 #append - adds to list scores.append(newscore) newscore = 8 scores.append(newscore) newscore = 4 scores.append(newscore) newscore = 2 scores.append(newscore) newscore = 5 scores.append(newscore) newscore = 8 scores.append(newscore) print(scores) #remove a score score = 8 if score in scores: scores.remove(score) print (scores) scores.reverse() print(scores) # sort scores scores.sort() print(scores) scores.sort(reverse = True) print(scores)

 count(value) – counts the number of times value occurs in list  index(value) – returns index of first occurrence of value  insert(f,value)- inserts value at position f  pop([f]) – returns value at position f and removes value from list. Without f, it pops the last element off the list  remove(value) – removes first occurrence of value from the list scores.append(3) scores.append(8) scores.append(3) print(scores) print(scores.count(3)) print(scores.index(3)) scores.insert(7, 4) print(scores) scores.pop() print(scores) scores.remove(5) print (scores)

import random def sl(list,new): if len(list) == 1: new.append(list.pop( )) return(new) else: x = random.randrange(0,len(list)) new.append(list.pop(x)) return(sl(list,new)) list = ["m","o","t","h","e","r"] new = [] print(sl(list,new))