p y thon lists
play

P y thon Lists IN TR OD U C TION TO P YTH ON H u go Bo w ne - - PowerPoint PPT Presentation

P y thon Lists IN TR OD U C TION TO P YTH ON H u go Bo w ne - Anderson Data Scientist at DataCamp P y thon Data T y pes oat - real n u mbers int - integer n u mbers str - string , te x t bool - Tr u e , False height = 1.73 tall = True Each


  1. P y thon Lists IN TR OD U C TION TO P YTH ON H u go Bo w ne - Anderson Data Scientist at DataCamp

  2. P y thon Data T y pes � oat - real n u mbers int - integer n u mbers str - string , te x t bool - Tr u e , False height = 1.73 tall = True Each v ariable represents single v al u e INTRODUCTION TO PYTHON

  3. Problem Data Science : man y data points Height of entire famil y height1 = 1.73 height2 = 1.68 height3 = 1.71 height4 = 1.89 Incon v enient INTRODUCTION TO PYTHON

  4. P y thon List [a, b, c] [1.73, 1.68, 1.71, 1.89] [1.73, 1.68, 1.71, 1.89] fam = [1.73, 1.68, 1.71, 1.89] fam [1.73, 1.68, 1.71, 1.89] Name a collection of v al u es Contain an y t y pe Contain di � erent t y pes INTRODUCTION TO PYTHON

  5. P y thon List [a, b, c] fam = ["liz", 1.73, "emma", 1.68, "mom", 1.71, "dad", 1.89] fam ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89] fam2 = [["liz", 1.73], ["emma", 1.68], ["mom", 1.71], ["dad", 1.89]] fam2 [['liz', 1.73], ['emma', 1.68], ['mom', 1.71], ['dad', 1.89]] INTRODUCTION TO PYTHON

  6. List t y pe type(fam) list type(fam2) list Speci � c f u nctionalit y Speci � c beha v ior INTRODUCTION TO PYTHON

  7. Let ' s practice ! IN TR OD U C TION TO P YTH ON

  8. S u bsetting Lists IN TR OD U C TION TO P YTH ON H u go Bo w ne - Anderson Data Scientist at DataCamp

  9. S u bsetting lists fam = ["liz", 1.73, "emma", 1.68, "mom", 1.71, "dad", 1.89] fam ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89] fam[3] 1.68 INTRODUCTION TO PYTHON

  10. S u bsetting lists ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89] fam[6] 'dad' fam[-1] 1.89 fam[7] 1.89 INTRODUCTION TO PYTHON

  11. S u bsetting lists ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89] fam[6] 'dad' fam[-1] # <- 1.89 fam[7] # <- 1.89 INTRODUCTION TO PYTHON

  12. List slicing fam ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89] fam[3:5] [1.68, 'mom'] fam[1:4] [1.73, 'emma', 1.68] INTRODUCTION TO PYTHON

  13. List slicing fam ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89] fam[:4] ['liz', 1.73, 'emma', 1.68] fam[5:] [1.71, 'dad', 1.89] INTRODUCTION TO PYTHON

  14. Let ' s practice ! IN TR OD U C TION TO P YTH ON

  15. Manip u lating Lists IN TR OD U C TION TO P YTH ON H u go Bo w ne - Anderson Data Scientist at DataCamp

  16. List Manip u lation Change list elements Add list elements Remo v e list elements INTRODUCTION TO PYTHON

  17. Changing list elements fam = ["liz", 1.73, "emma", 1.68, "mom", 1.71, "dad", 1.89] fam ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89] fam[7] = 1.86 fam ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.86] fam[0:2] = ["lisa", 1.74] fam ['lisa', 1.74, 'emma', 1.68, 'mom', 1.71, 'dad', 1.86] INTRODUCTION TO PYTHON

  18. Adding and remo v ing elements fam + ["me", 1.79] ['lisa', 1.74,'emma', 1.68, 'mom', 1.71, 'dad', 1.86, 'me', 1.79] fam_ext = fam + ["me", 1.79] del(fam[2]) fam ['lisa', 1.74, 1.68, 'mom', 1.71, 'dad', 1.86] INTRODUCTION TO PYTHON

  19. Behind the scenes (1) x = ["a", "b", "c"] INTRODUCTION TO PYTHON

  20. Behind the scenes (1) x = ["a", "b", "c"] y = x y[1] = "z" y ['a', 'z', 'c'] x ['a', 'z', 'c'] INTRODUCTION TO PYTHON

  21. Behind the scenes (1) x = ["a", "b", "c"] y = x y[1] = "z" y ['a', 'z', 'c'] x ['a', 'z', 'c'] INTRODUCTION TO PYTHON

  22. Behind the scenes (1) x = ["a", "b", "c"] y = x y[1] = "z" y ['a', 'z', 'c'] x ['a', 'z', 'c'] INTRODUCTION TO PYTHON

  23. Behind the scenes (2) x = ["a", "b", "c"] INTRODUCTION TO PYTHON

  24. Behind the scenes (2) x = ["a", "b", "c"] y = list(x) y = x[:] INTRODUCTION TO PYTHON

  25. Behind the scenes (2) x = ["a", "b", "c"] y = list(x) y = x[:] y[1] = "z" x ['a', 'b', 'c'] INTRODUCTION TO PYTHON

  26. Let ' s practice ! IN TR OD U C TION TO P YTH ON

Recommend


More recommend