MEIN 50010: Python Data Structures
|
|
- Paul Francis
- 6 years ago
- Views:
Transcription
1 : Python Data Structures Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday,
2 Data Structures Stacks, Queues & Deques Structures
3 Data structures are a way of storing & organising data Data structures help with managing large amounts of data Different kinds of data structures are suited to different kinds of application/problem Data structures should help in retrieving data efficiently Data structures may be customised for data being stored in main (cache, RAM, disk) or secondary memory (tape, DVD)
4 1/7 Motivation A list stores a number of elements in a specific order Elements are accessed using an integer (index) can be of fixed length or expandable/shrinkable Elements can be of almost any type (integer, double/float, character/string, record/structure, lists,...) and a mixture thereof (bad idea) Most other data structures are based on lists Everyone else (non-python) calls them arrays
5 2/7 Basics The easiest list is empty >>> emptylist=[] are declared with square brackets >>> num=[2,4,6,8,10,12] The type of this construct is >>> type(num) <type list > >>> type(num[0]) <type int > Indexing begins with 0, >>> num[0] 2 Negative indexing from the back >>> num[-1] 12 Range (slice) of elements accessed using colon >>> num[0:3] [2, 4, 6] not including num[3]! Loop through the elements >>> for a in num: print(a,) 2,4,6,8,10,12
6 List 3/7 Common Methods len(list) number of elements in the list >>> L=[1,2,3] >>> len(l) 3.append(value) appends element to end of list ( += ) >>> L=[1,2,3] >>> L.append(4) >>> L [1,2,3,4] >>> L=[1,2,3] >>> L.append([4,5]) >>> L [1,2,3,[4,5]] >>> len(l) 4.extend(list) concatenates lists (or + ) >>> L=[1,2,3] >>> L.extend([4,5]) >>> L [1,2,3,4,5] >>> len(l) 5.insert( y, x ) inserts x at location y >>> L=[1,2,3] >>> L.insert(1,4) >>> L [1,4,2,3].pop() - returns last element then removes it from list >>> L=[1,2,3]; >>> L.pop() >>> L 3; [1,2]
7 4/7 Common Methods.index( x ) returns index of first x in list >>> L=[1,2,3] >>> L.index(2) 1.remove( x ) finds and removes first x from list >>> L=[1,2,3] >>> L.remove(2) >>> L [1,3].reverse() - reverses the elements in the list >>> L=[1,2,3] >>> L.reverse() >>> L [3,2,1].sort() sorts the list alphabetically in ascending order, or numerical in ascending order >>> L=[3,2,1] >>> L.sort() >>> L [1,2,3] Cannot sort mixed lists like [ 1,2,3] in Python3 (used to work in Python2) Used to be able in Python2 to.replace( a, b ), in Python3 can use List Comprehension
8 5/7 Definitions A Stack is a data structure where elements are added and subtracted at the same end (LIFO - last in first out) adding and subtracting elements at the end is fast A Queue is a data structure where elements are added at one end and removed at the other end (FIFO - first in first out) adding elements at the end and subtracting at the head is slow because all elements have to be shifted that s why queues are usually implemented as deques A Deque is a double ended queue where elements can be added and/or subtracted at either end, preserving the order of the elements in the deque to implement a queue use collections.deque package from collections import deque.pop() to remove elements from end.popleft() to remove elements from head
9 6/7 Function Tools filter returns elements for which a condition is true >>> def even(x): return x % 2 == 0 >>> L=[1,2,3,4] >>> list(filter(even, L)) [2, 4] A function can be mapped onto each element of a list >>> def square(x): return x*x >>> list(map(square, L)) [1, 4, 9, 16] Map n-argument function onto n sequences >>> def f(x,y): return x + 1.0/y >>> list(map(f,l,l)) [2.0, 2.5, 3.333, 4.25] reduce a sequence by calling binary function >>> def add(x,y): return x+y >>> functools.reduce(add, list(range(1,11))) 55
10 7/7 List Comprehensions List comprehensions are a compact way to create lists Could build up list with append >>> Squares = [] >>> for x in range(1,5):... Squares.append(x*x) [1,4,9,16] Or could map a function >>> L=range(1,5) >>> Squares = map(square, L) Instead do everything in one step >>> Squares = [x*x for x in range(1,5)] List comprehensions can be nested >>> [[x,y] for x in L for y in L] [1,1], [1,2], [1,3], [1,4], [2,1],... [4,4] List comprehensions can have conditionals >>> [(x,y) for x in L for y in L if x<y] [(1,2), (1,3), (1,4), (2,3), (2,4), (3,4)]
11 are unordered collections of unique elements >>>mylist = [1,1,3,4,5,1,3,4,2] >>>mylist[2] # access by index 3 >>>myset=set(mylist) >>>myset {1, 2, 3, 4, 5} When turning list into set, duplicates are removed Order is not preserved (there is none) Cannot access elements by index (no order) >>>myset[1] TypeError: set object does not support indexing
12 really useful for comparing gene sets, e.g., all kinases found in nucleus but not cytoplasm or genes upregulated in condition A and condition B >>>myset1 = set([1,2,3,4]) >>>myset2 = set([3,4,5,6]) >>>myset1.union(myset2) [1, 2, 3, 4, 5, 6] >>>myset1.intersection(myset2) [3, 4] >>>myset1.difference(myset2) [1, 2]
13 1/2 are like lists, declared with (parentheses) instead of [square brackets], however, parentheses are optional but useful for clarity, comma is not optional! empty=(), singleton=1, are immutable (cannot be changed), but may contain mutable objects >>> T=(1,2,3) >>> T.append(4) Traceback (most recent call last): AttributeError: tuple object has no attribute append May be desirable if quantities are not meant to change can be cast as lists if they have to change >>> L=list(T) Conversely, lists can be tupled t=tuple(l) can be used to assign multiple values at once >>> t1=(1,2,3) >>> (a,b,c)=t1
14 2/2 Common Methods None
15 1/2 1-to-1 relationship between keys and values D={key1 : val1, key2 : val2... } >>> GerEng={ Hund : dog, Katze : cat } Can get values by key but cannot get key by value There is only one value per key, assigning a value to an existing key over-writes the old value Adding a new key/value extends the dictionary, >>> GerEng[ Kuh ] = cow Entries can be deleted with >>> del GerEng[ Hund ], the entire dictionary can be wiped with.clear() The order in which key/value pairs appear in the dictionary is random and likely to change as the dictionary is changed
16 2/2 Common Methods.keys() list all the keys in the dictionary.values() list all the values in the dictionary.items list both keys and values of the dictionary <key> in <dict> find if a key exists in the dictionary dict Example: if Kuh in GerEng:... print( yes ).has key(k) deprecated, Python2 only.update(d2) merge dictionary with dictionary D2
17 Data Structures (important) types of data structures, not covered here Trees Binary Multiway Trie Hashes Graphs
18 Picture Venn (mathematics)
Lists, Tuples and Dictionaries. HORT Lecture 10 Instructor: Kranthi Varala
Lists, Tuples and Dictionaries HORT 59000 Lecture 10 Instructor: Kranthi Varala Core data types Numbers Strings Lists Dictionaries Tuples Files Sets References and dynamic typing Dynamic typing allows
More informationModule 04: Lists. Topics: Lists and their methods Mutating lists Abstract list functions Readings: ThinkP 8, 10. CS116 Fall : Lists
Module 04: Lists Topics: Lists and their methods Mutating lists Abstract list functions Readings: ThinkP 8, 10 1 Consider the string method split >>> name = "Harry James Potter" >>> name.split() ['Harry',
More informationLECTURE 3 Python Basics Part 2
LECTURE 3 Python Basics Part 2 FUNCTIONAL PROGRAMMING TOOLS Last time, we covered function concepts in depth. We also mentioned that Python allows for the use of a special kind of function, a lambda function.
More informationSequences and iteration in Python
GC3: Grid Computing Competence Center Sequences and iteration in Python GC3: Grid Computing Competence Center, University of Zurich Sep. 11 12, 2013 Sequences Python provides a few built-in sequence classes:
More informationData Structures. Lists, Tuples, Sets, Dictionaries
Data Structures Lists, Tuples, Sets, Dictionaries Collections Programs work with simple values: integers, floats, booleans, strings Often, however, we need to work with collections of values (customers,
More informationData Structures. Dictionaries - stores a series of unsorted key/value pairs that are indexed using the keys and return the value.
Data Structures Lists - stores a series of ordered mutable items Tuples - stores a series of ordered immutable items [not commonly used] Sets - stores a series of mutable or immutable(frozen) unsorted
More informationChapter 8 Dictionaries. Dictionaries are mutable, unordered collections with elements in the form of a key:value pairs that associate keys to values.
Chapter 8 Dictionaries Dictionaries are mutable, unordered collections with elements in the form of a key:value pairs that associate keys to values. Creating a Dictionary To create a dictionary, you need
More informationLecture 7: Python s Built-in. in Types and Basic Statements
The University of North Carolina at Chapel Hill Spring 2002 Lecture 7: Python s Built-in in Types and Basic Statements Jan 25 1 Built-in in Data Structures: Lists A list is an ordered collection of objects
More informationCollections. Lists, Tuples, Sets, Dictionaries
Collections Lists, Tuples, Sets, Dictionaries Homework notes Homework 1 grades on canvas People mostly lost points for not reading the document carefully Didn t play again Didn t use Y/N for playing again
More informationCS2304: Python for Java Programmers. CS2304: Sequences and Collections
CS2304: Sequences and Collections Sequences In Python A sequence type in python supports: The in membership operator. The len() function. Slicing like we saw with strings, s[1:3]. And is iterable (for
More informationPython Lists. Stéphane Vialette. LIGM, Université Paris-Est Marne-la-Vallée. October 5, 2011
Python Lists Stéphane Vialette LIGM, Université Paris-Est Marne-la-Vallée October 5, 2011 Stéphane Vialette (LIGM UPEMLV) Python Lists October 5, 2011 1 / 31 Outline 1 Introduction 2 Methods 3 Lists as
More informationPython I. Some material adapted from Upenn cmpe391 slides and other sources
Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationCSC326 Python Sequences i. CSC326 Python Sequences
i CSC326 Python Sequences ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME 1.0 2011-09 JZ iii Contents 1 Agenda 1 2 while Statement 1 3 Sequence Overview 2 4 String 2 5 Lists 4 6 Dictionary 5 7 Tuples
More informationCSC148 Week 2. Larry Zhang
CSC148 Week 2 Larry Zhang 1 Admin Discussion board is up (link on the course website). 2 Outline for this week Abstract Data Type Stack Queue 3 Abstract Data Type (ADT) 4 What is an abstract data type
More informationIntroduction to Python! Lecture 2
.. Introduction to Python Lecture 2 Summary Summary: Lists Sets Tuples Variables while loop for loop Functions Names and values Passing parameters to functions Lists Characteristics of the Python lists
More informationCIS192: Python Programming Data Types & Comprehensions Harry Smith University of Pennsylvania September 6, 2017 Harry Smith (University of Pennsylvani
CIS192: Python Programming Data Types & Comprehensions Harry Smith University of Pennsylvania September 6, 2017 Harry Smith (University of Pennsylvania) CIS 192 Fall Lecture 2 September 6, 2017 1 / 34
More informationPython: Short Overview and Recap
Python: Short Overview and Recap Benjamin Roth CIS LMU Benjamin Roth (CIS LMU) Python: Short Overview and Recap 1 / 39 Data Types Object type Example creation Numbers (int, float) 123, 3.14 Strings this
More informationLISTS WITH PYTHON. José M. Garrido Department of Computer Science. May College of Computing and Software Engineering Kennesaw State University
LISTS WITH PYTHON José M. Garrido Department of Computer Science May 2015 College of Computing and Software Engineering Kennesaw State University c 2015, J. M. Garrido Lists with Python 2 Lists with Python
More informationA lot of people make repeated mistakes of not calling their functions and getting errors. Make sure you're calling your functions.
Handout 2 Functions, Lists, For Loops and Tuples [ ] Functions -- parameters/arguments, "calling" functions, return values, etc. Please make sure you understand this example: def square(x): return x *
More informationCIS192 Python Programming
CIS192 Python Programming Data Types Joseph Cappadona University of Pennsylvania September 03, 2015 Joseph Cappadona (University of Pennsylvania) CIS 192 September 03, 2015 1 / 32 Outline 1 Data Types
More informationCollections. John Perry. Fall 2011
MAT 305: Collections University of Southern Mississippi Fall 2011 Outline 1 2 3 4 Collections? Collection: group of objects identified as single object indexed tuples a 0, a 1, a 2,...a n points x 0, y
More informationMEIN 50010: Python Flow Control
: Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-11 Program Overview Program Code Block Statements Expressions Expressions & Statements An expression has
More informationPython Programming: Lecture 2 Data Types
Python Programming: Lecture 2 Data Types Lili Dworkin University of Pennsylvania Last Week s Quiz 1..pyc files contain byte code 2. The type of math.sqrt(9)/3 is float 3. The type of isinstance(5.5, float)
More informationMUTABLE LISTS AND DICTIONARIES 4
MUTABLE LISTS AND DICTIONARIES 4 COMPUTER SCIENCE 61A Sept. 24, 2012 1 Lists Lists are similar to tuples: the order of the data matters, their indices start at 0. The big difference is that lists are mutable
More informationNotebook. March 30, 2019
Notebook March 30, 2019 1 Complex Data Types Some kinds of data can store other kinds of data. 1.1 Lists We ve actually seen the most common complex data type a few times before, I just haven t pointed
More informationA Little Python Part 2
A Little Python Part 2 Introducing Programming with Python Data Structures, Program Control Outline Python and the System Data Structures Lists, Dictionaries Control Flow if, for, while Reminder - Learning
More informationSome material adapted from Upenn cmpe391 slides and other sources
Some material adapted from Upenn cmpe391 slides and other sources History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationThere are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:
Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited
More informationMEIN 50010: Python Introduction
: Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-04 Outline Goals Teach basic programming concepts Apply these concepts using Python Use Python Packages
More informationLists and Loops. browse Python docs and interactive help
Lists and Loops 1 Help in Python browse Python docs and interactive help 2 Lists in Python defining lists lists as queues and stacks inserting and removing membership and ordering lists 3 Loops in Python
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationJohn Perry. Fall 2009
Lecture 5: Sage University of Southern Mississippi Fall 2009 Outline 1 2 3 4 You should be in worksheet mode to repeat the examples. Collections? Collection: group of objects identified as single object
More informationPython for Non-programmers
Python for Non-programmers A Gentle Introduction 2 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
More informationIntroduction to Problem Solving and Programming in Python.
Introduction to Problem Solving and Programming in Python http://cis-linux1.temple.edu/~tuf80213/courses/temple/cis1051/ Overview Python sequences Lists, Tuples, and Ranges Built-in operations Slicing
More informationDM502 Programming A. Peter Schneider-Kamp.
DM502 Programming A Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm502/! PROJECT PART 1 2 Organizational Details 2 possible projects, each consisting of 2 parts for 1 st part,
More informationData Structures I: Linked Lists
Lab 4 Data Structures I: Linked Lists Lab Objective: Analyzing and manipulating data are essential skills in scientific computing. Storing, retrieving, and rearranging data take time. As a dataset grows,
More informationHistory Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability
History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Some material adapted from Upenn cmpe391 slides and other sources Invented in the Netherlands,
More informationThe Practice of Computing Using PYTHON
The Practice of Computing Using PYTHON William Punch Richard Enbody Chapter 6 Lists and Tuples 1 Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Data Structures 2 Data Structures
More informationList of squares. Program to generate a list containing squares of n integers starting from 0. list. Example. n = 12
List of squares Program to generate a list containing squares of n integers starting from 0 Example list n = 12 squares = [] for i in range(n): squares.append(i**2) print(squares) $ python3 squares.py
More informationDictionaries. Looking up English words in the dictionary. Python sequences and collections. Properties of sequences and collections
Looking up English words in the dictionary Comparing sequences to collections. Sequence : a group of things that come one after the other Collection : a group of (interesting) things brought together for
More informationWorksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords
Worksheet 1: Introductory Exercises Turtle Programming Calculations The Print Function Comments Syntax Semantics Strings Concatenation Quotation Marks Types Variables Restrictions on Variable Names Long
More informationBasic Scripting, Syntax, and Data Types in Python. Mteor 227 Fall 2017
Basic Scripting, Syntax, and Data Types in Python Mteor 227 Fall 2017 Basic Shell Scripting/Programming with Python Shell: a user interface for access to an operating system s services. The outer layer
More informationLecture Agenda. Objects. But First... Immutable Types and Nesting. Immutable Types and Nesting
COMP10001 Foundations of Computing Objects and Types: A Closer Look (Advanced Lecture) Semester 1, 2017 Tim Baldwin & Egemen Tanin Lecture Agenda This lecture: Making sense of strings, lists and functions
More informationAdvanced Python. Executive Summary, Session 1
Advanced Python Executive Summary, Session 1 OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or use with operators). Everything in Python is an object.
More informationRecap from last Python lecture
Recap from last Python lecture Interpreted, imperative, OO Language Everything is an object Dynamic Typing Programs are made up of: Expressions Statements Assignment if/elif/else while-loops Functions
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationPython Review IPRE
Python Review 2 Jay Summet 2005-12-31 IPRE Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing Elements Cloning Slices Mutable Types: Lists Dictionaries
More informationMITOCW watch?v=rvrkt-jxvko
MITOCW watch?v=rvrkt-jxvko The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To
More informationLists How lists are like strings
Lists How lists are like strings A Python list is a new type. Lists allow many of the same operations as strings. (See the table in Section 4.6 of the Python Standard Library Reference for operations supported
More informationCS 234 Python Review Part 2
CS 234 Python Review Part 2 Recap import function: define, return boolean, conditional, branching loop: for, range, while file: open, close, readlines string: split Classes Define blueprint for a custom
More informationGE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING
GE8151 - PROBLEM SOVING AND PYTHON PROGRAMMING Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING 1) Define Computer 2) Define algorithm 3) What are the two phases in algorithmic problem solving? 4) Why
More informationLists in Python CS 8: Introduction to Computer Science, Winter 2018 Lecture #10
Lists in Python CS 8: Introduction to Computer Science, Winter 2018 Lecture #10 Ziad Matni Dept. of Computer Science, UCSB Administrative Homework #5 is due today Homework #6 is out and DUE on MONDAY (3/5)
More informationPart I. Wei Tianwen. A Brief Introduction to Python. Part I. Wei Tianwen. Basics. Object Oriented Programming
2017 Table of contents 1 2 Integers and floats Integer int and float float are elementary numeric types in. integer >>> a=1 >>> a 1 >>> type (a) Integers and floats Integer int and float
More informationPython Programming Language
Python Programming Language Data Structure Sachin PVPPCOE December 22, 2015 Data types Basic objects: numbers(float, int, complex), strings, Tuples, lists, sets, & dictionaries Other data types: Modules,
More informationDay 6. COMP1006/1406 Summer M. Jason Hinek Carleton University
Day 6 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments Assignment 3 is due on Monday a quick look back abstract classes and interfaces casting objects abstract data
More informationAnnouncements. Project 2 due next Monday. Next Tuesday is review session; Midterm 1 on Wed., EE 129, 8:00 9:30pm
Project 2 due next Monday Next Tuesday is review session; Announcements Midterm 1 on Wed., EE 129, 8:00 9:30pm Project 3 to be posted Oct. 3 (next Wed) Preparing for the Midterm: Review Chapters 3-6 of
More informationCOMP 204: Dictionaries Recap & Sets
COMP 204: Dictionaries Recap & Sets Material from Carlos G. Oliver, Christopher J.F. Cameron October 10, 2018 1/21 Reminder Midterm on Wednesday October 17 at 6:30-8:00 pm. Assignment 2: numpy is allowed
More informationProgramming Languages
CSE 130 : Fall 2008 Programming Languages Lecture 12: What s in a Name? Ranjit Jhala UC San Diego A crash course in Python Interpreted, imperative, OO Language g Everything is an object Dynamic Typing
More informationCS S-02 Python 1. Most python references use examples involving spam, parrots (deceased), silly walks, and the like
CS662-2013S-02 Python 1 02-0: Python Name python comes from Monte Python s Flying Circus Most python references use examples involving spam, parrots (deceased), silly walks, and the like Interpreted language
More informationProgramming Languages
CSE 130 : Spring 2010 Programming Languages News PA 4 is up (Due Fri, 5pm) Lecture 12: Crash course in Python Ranjit Jhala UC San Diego MidtermGeneral Statistics Total of 80 points < 20 9 people Mean:
More informationIntroduction to Python. Fang (Cherry) Liu Ph.D. Scien5fic Compu5ng Consultant PACE GATECH
Introduction to Python Ph.D. Scien5fic Compu5ng Consultant PACE GATECH Things Covered What is Python? How to access Python environment? Fundamental elements in Python Variables (assignment, comparison,
More informationAll programs can be represented in terms of sequence, selection and iteration.
Python Lesson 3 Lists, for loops and while loops Suffolk One, Ipswich, 4:30 to 6:00 Tuesday Jan 28 Nicky Hughes All programs can be represented in terms of sequence, selection and iteration. 1 Computational
More informationPython Review IPRE
Python Review Jay Summet 2005-12-31 IPRE Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing Elements Cloning Slices Mutable Types: Lists Dictionaries
More informationVariable and Data Type 2
The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 3 Variable and Data Type 2 Eng. Ibraheem Lubbad March 2, 2017 Python Lists: Lists
More informationQuestion 1. Part (a) Part (b) December 2013 Final Examination Marking Scheme CSC 108 H1F. [13 marks] [4 marks] Consider this program:
Question 1. Part (a) [4 marks] Consider this program: [13 marks] def square(x): (number) -> number Write what this program prints, one line per box. There are more boxes than you need; leave unused ones
More information6.006 Recitation. Build
6.006 Recitation Build 2008.4 Outline Asymptotic Notation Merge-Sort Python Cost Model (maybe) docdist{5,6}.py Asymptotic Notation f1: 1,000 * n 0.635 500,000,000 F1 F2 F3 f2: n 375,000,000 250,000,000
More informationChapter 2: Lists, Arrays and Dictionaries
Chapter 2: Lists, Arrays and Dictionaries 1. Higher order organization of data In the previous chapter, we have seen the concept of scalar variables that define memory space in which we store a scalar,
More informationUniversity of Texas at Arlington, TX, USA
Dept. of Computer Science and Engineering University of Texas at Arlington, TX, USA Part of the science in computer science is the design and use of data structures and algorithms. As you go on in CS,
More informationDM550/DM857 Introduction to Programming. Peter Schneider-Kamp
DM550/DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ HANDLING TEXT FILES 2 Reading Files open files
More informationAdvanced Algorithms and Computational Models (module A)
Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value
More informationPython Compact. 1 Python Compact. 2 What do we cover in this introduction lecture? February 7, What is also interesting to know?
Python Compact February 7, 2018 1 Python Compact 1.0.1 Claus Führer, Lund University Short introduction to Python for participants of the course ** Numerical Methods - Review and Training ** Volvo Cars,
More informationComputer Sciences 368 Scripting for CHTC Day 3: Collections Suggested reading: Learning Python
Day 3: Collections Suggested reading: Learning Python (3rd Ed.) Chapter 8: Lists and Dictionaries Chapter 9: Tuples, Files, and Everything Else Chapter 13: while and for Loops 1 Turn In Homework 2 Homework
More informationDSC 201: Data Analysis & Visualization
DSC 201: Data Analysis & Visualization Arrays Dr. David Koop Class Example class Rectangle: def init (self, x, y, w, h): self.x = x self.y = y self.w = w self.h = h def set_corner(self, x, y): self.x =
More informationDictionaries. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region. Based on CBSE Curriculum Class -11. Neha Tyagi, KV 5 Jaipur II Shift
Dictionaries Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Introduction Python provides us various options to store multiple values under one variable name.
More informationCMPT 120 Lists and Strings. Summer 2012 Instructor: Hassan Khosravi
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi All of the variables that we have used have held a single item One integer, floating point value, or string often you find that you want
More informationpython 01 September 16, 2016
python 01 September 16, 2016 1 Introduction to Python adapted from Steve Phelps lectures - (http://sphelps.net) 2 Python is interpreted Python is an interpreted language (Java and C are not). In [1]: 7
More informationPython and Bioinformatics. Pierre Parutto
Python and Bioinformatics Pierre Parutto October 9, 2016 Contents 1 Common Data Structures 2 1.1 Sequences............................... 2 1.1.1 Manipulating Sequences................... 2 1.1.2 String.............................
More informationMEIN 50010: Python Strings
: Python Strings Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-25 Lecture Basic string manipulation Converting between different variable types strings Command-line
More informationPython - Variable Types. John R. Woodward
Python - Variable Types John R. Woodward Variables 1. Variables are nothing but named reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
More informationScript language: Python Data structures
Script language: Python Data structures Cédric Saule Technische Fakultät Universität Bielefeld 3. Februar 2015 Immutable vs. Mutable Previously known types: int and string. Both are Immutable but what
More informationPractical Workbook Computer Programming
Practical Workbook Computer Programming Name Year Batch Roll No Department: 5 th Edition Fall 2017-2018 Dept. of Computer & Information Systems Engineering NED University of Engineering & Technology, Karachi
More informationLecture 12 ADTs and Stacks
Lecture 12 ADTs and Stacks Modularity Divide the program into smaller parts Advantages Keeps the complexity managable Isolates errors (parts can be tested independently) Can replace parts easily Eliminates
More informationPython. Executive Summary
Python Executive Summary DEFINITIONS OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or response to operators). Everything in Python is an object. "atomic"
More informationSequence types. str and bytes are sequence types Sequence types have several operations defined for them. Sequence Types. Python
Python Sequence Types Sequence types str and bytes are sequence types Sequence types have several operations defined for them Indexing Python Sequence Types Each element in a sequence can be extracted
More informationRecap from last Python lecture. Today: Revisit some objects. Update subsequence. What can sequences do? Update subsequence.
Recap from last Python lecture Interpreted, imperative, OO Language Everything is an object Dynamic Typing Programs are made up of: Expressions Statements Assignment if/elif/else while-loops Functions
More informationShort Python function/method descriptions:
Last Name First Name Student#. Short Python function/method descriptions: builtins : len(x) -> integer Return the length of the list, tuple, dict, or string x. max(l) -> value Return the largest value
More informationAI Programming CS S-02 Python
AI Programming CS662-2013S-02 Python David Galles Department of Computer Science University of San Francisco 02-0: Python Name python comes from Monte Python s Flying Circus Most python references use
More informationHere n is a variable name. The value of that variable is 176.
UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence
More informationLab 6: Data Types, Mutability, Sorting. Ling 1330/2330: Computational Linguistics Na-Rae Han
Lab 6: Data Types, Mutability, Sorting Ling 1330/2330: Computational Linguistics Na-Rae Han Objectives Data types and conversion Tuple Mutability Sorting: additional parameters Text processing overview
More informationPython Lists: Example 1: >>> items=["apple", "orange",100,25.5] >>> items[0] 'apple' >>> 3*items[:2]
Python Lists: Lists are Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). All the items belonging to a list can be of different data type.
More informationEpisode 3 Lists and Strings
Episode 3 Lists and Strings Lists and strings are two of the most important types in Python. For these, one variable name stands for several items, so we call them compound types. Lists Lists are much
More informationNumbers, lists and tuples. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
Numbers, lists and tuples Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Numbers Python defines various types of numbers: Integer (1234) Floating point number
More informationPython. Karin Lagesen.
Python Karin Lagesen karin.lagesen@bio.uio.no Plan for the day Basic data types data manipulation Flow control and file handling Functions Biopython package What is programming? Programming: ordered set
More informationPart 4 CLASSES AS ABSTRACT DATA TYPES AND INTERFACE IMPLEMENTATION. Data Structures and Algorithms 31632
Part 4 CLASSES AS ABSTRACT DATA TYPES AND INTERFACE IMPLEMENTATION 1 ADT ABSTRACT DATA TYPE 2 Abstract Data Type (ADT) A programmer-defined data type that specifies a set of data values and a collection
More informationCOMP1730/COMP6730 Programming for Scientists. Dictionaries and sets
COMP1730/COMP6730 Programming for Scientists Dictionaries and sets Lecture outline * Mappings: the dict type. * Sets: the set type. Mappings * A mapping (a.k.a. dictionary) stores key value pairs; each
More informationData Structure in Python for Data Analytics Prof. Zhang CISC5835, Fall Basic Built-in Python Data Structures
Data Structure in Python for Data Analytics Prof. Zhang CISC5835, Fall 2018 It s important to know basic data structures and understand the performance impacts of choosing a certain data structure (i.e.,
More informationPython in 10 (50) minutes
Python in 10 (50) minutes https://www.stavros.io/tutorials/python/ Python for Microcontrollers Getting started with MicroPython Donald Norris, McGrawHill (2017) Python is strongly typed (i.e. types are
More informationPLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science
PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2013 EXAMINATIONS CSC 108 H1F Instructors: Craig and Gries Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number:
More informationCS Advanced Unix Tools & Scripting
& Scripting Spring 2011 Hussam Abu-Libdeh slides by David Slater March 4, 2011 Hussam Abu-Libdeh slides by David Slater & Scripting Python An open source programming language conceived in the late 1980s.
More informationBasic Python Revision Notes With help from Nitish Mittal
Basic Python Revision Notes With help from Nitish Mittal HELP from Documentation dir(module) help() Important Characters and Sets of Characters tab \t new line \n backslash \\ string " " or ' ' docstring
More information