MIT Open Class: Python notes 7 list and variability, dictionary, efficiency

Source: Internet
Author: User

Lecture 7:lists and mutability,dictionaries,pseudocode,introduction to efficiency list and variability, dictionary, pseudo Code, efficiency Lists and mutability List and variability
>>> L1 = [123]>>> L2 = L1>>> print L2[123]>>> L1[04>>> print L2[423]
 def F(L):l[0] =4L1 = [1,2,3]L2 = [1,2,3]L3 = L1PrintL1 = = L2F (L1)PrintL1 = = L2PrintL1PrintL2PrintL3#输出TrueFalse[4,2,3][1,2,3][4,2,3]
Dictionaries dictionary

3wschool Python Dictionary

    • Mutable can be changed.
    • Not ordered unordered
    • Generalized indexing Index
    • Key, value pair key value pair
    • -
Etof = {' One ':' UN ',' Soccer ':' Football '}Printetof[' Soccer ']Printetof[0]PrintEtofntos = {1:' One ',2:' both ',' One ':1,' both ':2}PrintNtos.keys ()PrintNtos.keysdelntos[' One ']PrintNTOSL = [[' UN ',' One '], [' deux ',' both ']] def keysearch(L, k):     forEleminchLifelem[0] = = k:returnelem[1]return NonePrintKeysearch (L,' deux ')# OutputFootballPrintetof[0]keyerror:0{' Soccer ':' Football ',' One ':' UN '}[1,2,' both ',' One ']<built-inchMethod Keys of Dict object at0x7fc52bf0b1e0>{1:' One ',2:' both ',' both ':2}two
Pseudo Code Pseudocode

To seek the hypotenuse of right triangle:

    • Input value for base enter bottom edge as float
    • Input value for height enter high as float
    • sqrt (base**2 + height **2) Compute hypotenuse
    • Output value in hypotenuse outputs
ImportMath# Get BaseInputok =False while  notInputok:base = input (' Enter base: ')ifType (Base) = = Type (1.0): Inputok =True    Else: Print (' Error. Base must is floating point number. ')# Get HeightInputok =False while  notInputok:height = input (' Enter height: ')ifType (height) = = Type (1.0): Inputok =True    Else: Print (' Error. Height must is floating point number. ') Hyp = math.sqrt (Base * base + Height * height)Print ' Base: '+ STR (base) +', Height: '+ str (height) +', Hyp: '+ STR (HYP)

Improved:

 def getfloat(requestmsg, errormsg):Inputok =False     while  notInputok:val = input (requestmsg)ifType (val) = = Type (1.0): Inputok =True        Else: Print (ERRORMSG)returnValbase = GetFloat (' Enter base: ',' error:base must be a float ') height = getfloat (' Enter height: ',' error:height must be a float ') Hyp = math.sqrt (Base * base + Height * height)Print ' Base: '+ STR (base) +', Height: '+ str (height) +', Hyp: '+ STR (HYP)
Efficiency efficiency efficiency–orders of growth
    • Choice of algorithm algorithm selection
    • Map a problem into a class of algorithms of some efficiency maps the problem to an efficient algorithm
Space & Time & Spaces
    • How much memory does it takes to consume as much storage space
    • What is the number of the the basic steps needed as a function of the input size the method of calculation has several steps

Random access model

    • Best Case–min
    • Worst Case–max
    • Expected CASE–AVG

MIT Open Class: Python notes 7 list and variability, dictionary, efficiency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.