SlideShare ist ein Scribd-Unternehmen logo
1 von 61
Downloaden Sie, um offline zu lesen
Data Structures in Python
                                   Crash Course

                                 Dr.Haitham A. El-Ghareeb

                                  Information Systems Department
                           Faculty of Computers and Information Sciences
                                        Mansoura University
                                       helghareeb@gmail.com


                                      December 9, 2012




Dr.Haitham A. El-Ghareeb (CIS)     Data Structures and Algorithms - 2012   December 9, 2012   1 / 61
Agenda	
  
    •    Whe*ng	
  Your	
  Appe0te	
  
    •    Using	
  Python	
  Interpreter	
  
    •    Informal	
  Introduc0on	
  to	
  Python	
  
    •    More	
  Control	
  Flows	
  
    •    Data	
  Structures	
  
    •    Modules	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   2 / 61
Python	
  
    •  Easy	
  to	
  learn,	
  powerful	
  programming	
  
       language.	
  
    •  Has	
  efficient	
  high-­‐level	
  data	
  structures	
  and	
  a	
  
       simple	
  but	
  effec0ve	
  approach	
  to	
  object-­‐
       oriented	
  programming.	
  
        –  elegant	
  syntax	
  	
  
        –  dynamic	
  typing	
  
        –  interpreted	
  nature	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012        December 9, 2012   3 / 61
Python	
  
    •    Simpler	
  to	
  use	
  
    •    Available	
  on	
  Windows,	
  Mac	
  OS	
  X,	
  and	
  Unix	
  
    •    Help	
  you	
  get	
  the	
  job	
  done	
  more	
  quickly	
  
    •    Split	
  your	
  program	
  into	
  modules	
  that	
  can	
  be	
  reused	
  
    •  Python	
  is	
  an	
  interpreted	
  language:	
  
          –  Save	
  you	
  considerable	
  0me	
  during	
  program	
  
             development	
  because	
  no	
  compila0on	
  and	
  linking	
  
             is	
  necessary.	
  	
  
          –  Interpreter	
  can	
  be	
  used	
  interac0vely	
  




Dr.Haitham A. El-Ghareeb (CIS)        Data Structures and Algorithms - 2012               December 9, 2012   4 / 61
Python	
  
    •  Python	
  is	
  extensible:	
  if	
  you	
  know	
  how	
  to	
  
       program	
  in	
  C	
  it	
  is	
  easy	
  to	
  add	
  a	
  new	
  built-­‐in	
  
       func0on	
  or	
  module	
  to	
  the	
  interpreter,	
  
    •  Named	
  aSer	
  the	
  BBC	
  show	
  “Monty	
  Python’s	
  
       Flying	
  Circus”	
  and	
  has	
  nothing	
  to	
  do	
  with	
  
       rep0les.	
  




Dr.Haitham A. El-Ghareeb (CIS)        Data Structures and Algorithms - 2012                December 9, 2012   5 / 61
Using	
  the	
  Python	
  Interpreter	
  
    •  Python	
  interpreter	
  is	
  usually	
  installed	
  as	
  /usr/
       local/bin/python	
  
    •  Invoking	
  the	
  Interpreter	
  
        –  A	
  second	
  way	
  of	
  star0ng	
  the	
  interpreter	
  is	
  python	
  
           -­‐c	
  command	
  [arg]	
  ...,	
  which	
  executes	
  the	
  
           statement(s)	
  in	
  command	
  
        –  Some	
  Python	
  modules	
  are	
  also	
  useful	
  as	
  scripts.	
  
           These	
  can	
  be	
  invoked	
  using	
  python	
  -­‐m	
  module	
  
           [arg]	
  ...,	
  which	
  executes	
  the	
  source	
  file	
  for	
  module	
  




Dr.Haitham A. El-Ghareeb (CIS)       Data Structures and Algorithms - 2012              December 9, 2012   6 / 61
Using	
  Python	
  Interpreter	
  
    •  Argument	
  Passing	
  
    •  Interac0ve	
  Mode	
  




    •  Error	
  Handling	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   7 / 61
Executable	
  Python	
  Scripts	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   8 / 61
Source	
  Code	
  Encoding	
  
    •  It	
  is	
  possible	
  to	
  use	
  encodings	
  different	
  than	
  
       ASCII	
  in	
  Python	
  source	
  files.	
  	
  
    •  The	
  best	
  way	
  to	
  do	
  it	
  is	
  to	
  put	
  one	
  more	
  
       special	
  comment	
  line	
  right	
  aSer	
  the	
  #!	
  line	
  to	
  
       define	
  the	
  source	
  file	
  encoding:	
  




Dr.Haitham A. El-Ghareeb (CIS)     Data Structures and Algorithms - 2012            December 9, 2012   9 / 61
Informal	
  Introduc0on	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   10 / 61
Using	
  Python	
  as	
  a	
  Calculator	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   11 / 61
Numbers	
  




Dr.Haitham A. El-Ghareeb (CIS)    Data Structures and Algorithms - 2012   December 9, 2012   12 / 61
Strings	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   13 / 61
Strings	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   14 / 61
String	
  Concatena0on	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   15 / 61
String	
  Indexing	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   16 / 61
String	
  Slicing	
  




Dr.Haitham A. El-Ghareeb (CIS)       Data Structures and Algorithms - 2012   December 9, 2012   17 / 61
Strings	
  are	
  Immutable!	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   18 / 61
Indices	
  May	
  be	
  Nega0ve	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   19 / 61
How	
  Come?!	
  




Dr.Haitham A. El-Ghareeb (CIS)      Data Structures and Algorithms - 2012   December 9, 2012   20 / 61
Lists	
  
    •  compound	
  data	
  type	
  
    •  used	
  to	
  group	
  together	
  other	
  values	
  	
  
    •  The	
  most	
  versa0le	
  
    •  can	
  be	
  wricen	
  as	
  a	
  list	
  of	
  comma-­‐separated	
  
       values	
  (items)	
  between	
  square	
  brackets.	
  	
  
    •  List	
  items	
  need	
  not	
  all	
  have	
  the	
  same	
  type.	
  




Dr.Haitham A. El-Ghareeb (CIS)     Data Structures and Algorithms - 2012         December 9, 2012   21 / 61
Shallow	
  Copy	
  




Dr.Haitham A. El-Ghareeb (CIS)       Data Structures and Algorithms - 2012   December 9, 2012   22 / 61
First	
  Steps	
  toward	
  Programming	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   23 / 61
More	
  Control	
  Flow	
  Tools	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   24 / 61
If	
  Statement	
  




Dr.Haitham A. El-Ghareeb (CIS)      Data Structures and Algorithms - 2012   December 9, 2012   25 / 61
For	
  Statement	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   26 / 61
For	
  Statement	
  with	
  Shallow	
  Copy	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   27 / 61
Range	
  Func0on	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   28 / 61
Break,	
  Con0nue,	
  Else	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   29 / 61
Pass	
  
    •  Does	
  Nothing!	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   30 / 61
Func0ons	
  




Dr.Haitham A. El-Ghareeb (CIS)    Data Structures and Algorithms - 2012   December 9, 2012   31 / 61
Return	
  Statement	
  	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   32 / 61
Default	
  Argument	
  Value	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   33 / 61
Documenta0on	
  String	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   34 / 61
Coding	
  Style	
  -­‐	
  PEP8	
  
    •  Use	
  4-­‐space	
  indenta0on,	
  and	
  no	
  tabs.	
  
    •  4	
  spaces	
  are	
  a	
  good	
  compromise	
  between	
  small	
  
       indenta0on	
  (allows	
  greater	
  nes0ng	
  depth)	
  and	
  large	
  
       indenta0on	
  (easier	
  to	
  read).	
  Tabs	
  introduce	
  confusion,	
  
       and	
  are	
  best	
  leS	
  out.	
  
    •  Wrap	
  lines	
  so	
  that	
  they	
  don’t	
  exceed	
  79	
  characters.	
  
    •  This	
  helps	
  users	
  with	
  small	
  displays	
  and	
  makes	
  it	
  
       possible	
  to	
  have	
  several	
  code	
  files	
  side-­‐by-­‐side	
  on	
  
       larger	
  displays.	
  
    •  Use	
  blank	
  lines	
  to	
  separate	
  func0ons	
  and	
  classes,	
  and	
  
       larger	
  blocks	
  of	
  code	
  inside	
  func0ons.	
  




Dr.Haitham A. El-Ghareeb (CIS)       Data Structures and Algorithms - 2012           December 9, 2012   35 / 61
Coding	
  Style	
  -­‐	
  PEP8	
  
    •  When	
  possible,	
  put	
  comments	
  on	
  a	
  line	
  of	
  their	
  own.	
  
    •  Use	
  docstrings.	
  
    •  Use	
  spaces	
  around	
  operators	
  and	
  aSer	
  commas,	
  but	
  not	
  
       directly	
  inside	
  bracke0ng	
  constructs:	
  a	
  =	
  f(1,	
  2)	
  +	
  g(3,	
  4).	
  
    •  Name	
  your	
  classes	
  and	
  func0ons	
  consistently;	
  the	
  
       conven0on	
  is	
  to	
  use	
  CamelCase	
  for	
  classes	
  and	
  
       lower_case_with_underscores	
  for	
  func0ons	
  and	
  methods.	
  
       Always	
  use	
  self	
  as	
  the	
  name	
  for	
  the	
  first	
  method	
  argument.	
  
    •  Don’t	
  use	
  fancy	
  encodings	
  if	
  your	
  code	
  is	
  meant	
  to	
  be	
  used	
  
       in	
  interna0onal	
  environments.	
  Plain	
  ASCII	
  works	
  best	
  in	
  any	
  
       case.	
  




Dr.Haitham A. El-Ghareeb (CIS)            Data Structures and Algorithms - 2012                   December 9, 2012   36 / 61
Data	
  Structures	
  -­‐	
  Lists	
  
    •  list.append(x)	
  Add	
  an	
  item	
  to	
  the	
  end	
  of	
  the	
  list.	
  
    •  list.extend(L)	
  Extend	
  the	
  list	
  by	
  appending	
  all	
  the	
  
       items	
  in	
  the	
  given	
  list.	
  
    •  list.insert(i,	
  x)	
  Insert	
  an	
  item	
  at	
  a	
  given	
  posi0on.	
  
       The	
  first	
  argument	
  is	
  the	
  index	
  of	
  the	
  element	
  
       before	
  which	
  to	
  insert,	
  so	
  a.insert(0,	
  x)	
  inserts	
  at	
  
       the	
  front	
  of	
  the	
  list,	
  and	
  a.insert(len(a),	
  x)	
  is	
  
       equivalent	
  to	
  a.append(x).	
  
    •  list.remove(x)	
  Remove	
  the	
  first	
  item	
  from	
  the	
  list	
  
       whose	
  value	
  is	
  x.	
  It	
  is	
  an	
  error	
  if	
  there	
  is	
  no	
  such	
  
       item.	
  




Dr.Haitham A. El-Ghareeb (CIS)            Data Structures and Algorithms - 2012                 December 9, 2012   37 / 61
Data	
  Structures	
  -­‐	
  Lists	
  
    •  list.pop([i])	
  Remove	
  the	
  item	
  at	
  the	
  given	
  posi0on	
  in	
  
       the	
  list,	
  and	
  return	
  it.	
  If	
  no	
  index	
  is	
  specified,	
  a.pop()	
  
       removes	
  and	
  returns	
  the	
  last	
  item	
  in	
  the	
  list.	
  	
  
    •  list.index(x)	
  Return	
  the	
  index	
  in	
  the	
  list	
  of	
  the	
  first	
  item	
  
       whose	
  value	
  is	
  x.	
  It	
  is	
  an	
  error	
  if	
  there	
  is	
  no	
  such	
  item.	
  
    •  list.count(x)	
  Return	
  the	
  number	
  of	
  0mes	
  x	
  appears	
  in	
  
       the	
  list.	
  
    •  list.sort()	
  Sort	
  the	
  items	
  of	
  the	
  list,	
  in	
  place.	
  
    •  list.reverse()	
  Reverse	
  the	
  elements	
  of	
  the	
  list,	
  in	
  place.	
  




Dr.Haitham A. El-Ghareeb (CIS)               Data Structures and Algorithms - 2012                      December 9, 2012   38 / 61
Lists	
  Example	
  




Dr.Haitham A. El-Ghareeb (CIS)       Data Structures and Algorithms - 2012   December 9, 2012   39 / 61
Using	
  Lists	
  as	
  Stack	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   40 / 61
Using	
  List	
  as	
  a	
  Queue	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   41 / 61
Func0onal	
  Programming	
  Tools	
  
    •  There	
  are	
  three	
  built-­‐in	
  func0ons	
  that	
  are	
  very	
  
       useful	
  when	
  used	
  with	
  lists:	
  filter(),	
  map(),	
  and	
  
       reduce().	
  




Dr.Haitham A. El-Ghareeb (CIS)    Data Structures and Algorithms - 2012       December 9, 2012   42 / 61
Filter()	
  
    •  filter(func0on,	
  sequence)	
  returns	
  a	
  sequence	
  
       consis0ng	
  of	
  those	
  items	
  from	
  the	
  sequence	
  
       for	
  which	
  func0on(item)	
  is	
  true.	
  	
  
    •  If	
  sequence	
  is	
  a	
  string	
  or	
  tuple,	
  the	
  result	
  will	
  
       be	
  of	
  the	
  same	
  type;	
  otherwise,	
  it	
  is	
  always	
  a	
  
       list.	
  	
  
    •  For	
  example,	
  to	
  compute	
  a	
  sequence	
  of	
  
       numbers	
  not	
  divisible	
  by	
  2	
  and	
  3:	
  




Dr.Haitham A. El-Ghareeb (CIS)       Data Structures and Algorithms - 2012            December 9, 2012   43 / 61
Filter()	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   44 / 61
Map()	
  
    •  map(func0on,	
  sequence)	
  calls	
  func0on(item)	
  
       for	
  each	
  of	
  the	
  sequence’s	
  items	
  and	
  returns	
  a	
  
       list	
  of	
  the	
  return	
  values.	
  	
  
    •  For	
  example,	
  to	
  compute	
  some	
  cubes:	
  




Dr.Haitham A. El-Ghareeb (CIS)    Data Structures and Algorithms - 2012       December 9, 2012   45 / 61
Map()	
  
    •  More	
  than	
  one	
  sequence	
  may	
  be	
  passed;	
  the	
  
       func0on	
  must	
  then	
  have	
  as	
  many	
  arguments	
  
       as	
  there	
  are	
  sequences	
  and	
  is	
  called	
  with	
  the	
  
       corresponding	
  item	
  from	
  each	
  sequence	
  (or	
  
       None	
  if	
  some	
  sequence	
  is	
  shorter	
  than	
  
       another).	
  For	
  example:	
  




Dr.Haitham A. El-Ghareeb (CIS)     Data Structures and Algorithms - 2012       December 9, 2012   46 / 61
Reduce()	
  
    •  reduce(func0on,	
  sequence)	
  returns	
  a	
  single	
  
       value	
  constructed	
  by	
  calling	
  the	
  binary	
  
       func0on	
  func2on	
  on	
  the	
  first	
  two	
  items	
  of	
  the	
  
       sequence,	
  then	
  on	
  the	
  result	
  and	
  the	
  next	
  
       item,	
  and	
  so	
  on.	
  	
  
    •  For	
  example,	
  to	
  compute	
  the	
  sum	
  of	
  the	
  
       numbers	
  1	
  through	
  10:	
  




Dr.Haitham A. El-Ghareeb (CIS)    Data Structures and Algorithms - 2012      December 9, 2012   47 / 61
Tuples	
  and	
  Sequences	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   48 / 61
Comma	
  at	
  the	
  end!	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   49 / 61
Sets	
  
    •  A	
  set	
  is	
  an	
  unordered	
  collec0on	
  with	
  no	
  
       duplicate	
  elements.	
  	
  
    •  Basic	
  uses	
  include	
  membership	
  tes0ng	
  and	
  
       elimina0ng	
  duplicate	
  entries.	
  	
  
    •  Set	
  objects	
  also	
  support	
  mathema0cal	
  
       opera0ons	
  like	
  union,	
  intersec0on,	
  difference,	
  
       and	
  symmetric	
  difference.	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   50 / 61
Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   51 / 61
Dic0onaries	
  
    •  Dic0onaries	
  are	
  some0mes	
  found	
  in	
  other	
  
       languages	
  as	
  “associa0ve	
  memories”	
  or	
  
       “associa0ve	
  arrays”.	
  	
  
    •  Unlike	
  sequences,	
  which	
  are	
  indexed	
  by	
  a	
  range	
  
       of	
  numbers,	
  dic0onaries	
  are	
  indexed	
  by	
  keys,	
  
       which	
  can	
  be	
  any	
  immutable	
  type;	
  strings	
  and	
  
       numbers	
  can	
  always	
  be	
  keys.	
  	
  
    •  Tuples	
  can	
  be	
  used	
  as	
  keys	
  if	
  they	
  contain	
  only	
  
       strings,	
  numbers,	
  or	
  tuples;	
  if	
  a	
  tuple	
  contains	
  
       any	
  mutable	
  object	
  either	
  directly	
  or	
  indirectly,	
  it	
  
       cannot	
  be	
  used	
  as	
  a	
  key.	
  	
  




Dr.Haitham A. El-Ghareeb (CIS)      Data Structures and Algorithms - 2012         December 9, 2012   52 / 61
Dic0onaries	
  
    •  You	
  can’t	
  use	
  lists	
  as	
  keys,	
  since	
  lists	
  can	
  be	
  modified	
  in	
  
       place	
  using	
  index	
  assignments,	
  slice	
  assignments,	
  or	
  
       methods	
  like	
  append()	
  and	
  extend().	
  
    •  It	
  is	
  best	
  to	
  think	
  of	
  a	
  dic0onary	
  as	
  an	
  unordered	
  set	
  of	
  
       key:	
  value	
  pairs,	
  with	
  the	
  requirement	
  that	
  the	
  keys	
  
       are	
  unique	
  (within	
  one	
  dic0onary).	
  	
  
    •  A	
  pair	
  of	
  braces	
  creates	
  an	
  empty	
  dic0onary:	
  {}.	
  Placing	
  
       a	
  comma-­‐separated	
  list	
  of	
  key:value	
  pairs	
  within	
  the	
  
       braces	
  adds	
  ini0al	
  key:value	
  pairs	
  to	
  the	
  dic0onary;	
  
       this	
  is	
  also	
  the	
  way	
  dic0onaries	
  are	
  wricen	
  on	
  output.	
  




Dr.Haitham A. El-Ghareeb (CIS)             Data Structures and Algorithms - 2012                    December 9, 2012   53 / 61
Dic0onaries	
  
    •  The	
  main	
  opera0ons	
  on	
  a	
  dic0onary	
  are	
  storing	
  a	
  value	
  
       with	
  some	
  key	
  and	
  extrac0ng	
  the	
  value	
  given	
  the	
  key.	
  
    •  It	
  is	
  also	
  possible	
  to	
  delete	
  a	
  key:value	
  pair	
  with	
  del.	
  If	
  
       you	
  store	
  using	
  a	
  key	
  that	
  is	
  already	
  in	
  use,	
  the	
  old	
  
       value	
  associated	
  with	
  that	
  key	
  is	
  forgocen.	
  It	
  is	
  an	
  
       error	
  to	
  extract	
  a	
  value	
  using	
  a	
  non-­‐existent	
  key.	
  
    •  The	
  keys()	
  method	
  of	
  a	
  dic0onary	
  object	
  returns	
  a	
  list	
  
       of	
  all	
  the	
  keys	
  used	
  in	
  the	
  dic0onary,	
  in	
  arbitrary	
  order	
  
       (if	
  you	
  want	
  it	
  sorted,	
  just	
  apply	
  the	
  sorted()	
  func0on	
  
       to	
  it).	
  	
  
    •  To	
  check	
  whether	
  a	
  single	
  key	
  is	
  in	
  the	
  dic0onary,	
  use	
  
       the	
  in	
  keyword.	
  




Dr.Haitham A. El-Ghareeb (CIS)             Data Structures and Algorithms - 2012                   December 9, 2012   54 / 61
Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   55 / 61
Dict()	
  Constructor	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   56 / 61
Looping	
  Techniques	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   57 / 61
Looping	
  over	
  Two	
  Sequences	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   58 / 61
Loop	
  in	
  Reverse	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   59 / 61
More	
  on	
  Condi0ons	
  
    •  Include	
  and,	
  or	
  




Dr.Haitham A. El-Ghareeb (CIS)     Data Structures and Algorithms - 2012   December 9, 2012   60 / 61
Comparing	
  Objects	
  of	
  Different	
  Types	
  




Dr.Haitham A. El-Ghareeb (CIS)   Data Structures and Algorithms - 2012   December 9, 2012   61 / 61

Weitere ähnliche Inhalte

Was ist angesagt?

Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and PackagesDamian T. Gordon
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methodsnarmadhakin
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Muhammad Hammad Waseem
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiersNilimesh Halder
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsMohamed Loey
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturergomathi chlm
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonPriyankaC44
 
Python Pandas
Python PandasPython Pandas
Python PandasSunil OS
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data StructureJeanie Arnoco
 

Was ist angesagt? (20)

Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Linked list
Linked listLinked list
Linked list
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
C# program structure
C# program structureC# program structure
C# program structure
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
CS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna UniversityCS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna University
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
 
Heaps
HeapsHeaps
Heaps
 
Shift reduce parser
Shift reduce parserShift reduce parser
Shift reduce parser
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 

Andere mochten auch

Andere mochten auch (7)

DSA-Lecture-05
DSA-Lecture-05DSA-Lecture-05
DSA-Lecture-05
 
Research Methodologies - Lecture 02
Research Methodologies - Lecture 02Research Methodologies - Lecture 02
Research Methodologies - Lecture 02
 
Learn Latex
Learn LatexLearn Latex
Learn Latex
 
DSA - Lecture 04
DSA - Lecture 04DSA - Lecture 04
DSA - Lecture 04
 
Python data structures(University of michigan)
Python data structures(University of michigan)Python data structures(University of michigan)
Python data structures(University of michigan)
 
Sample chapters [data structure and algorithmic thinking with python]
Sample chapters [data structure and algorithmic thinking with python]Sample chapters [data structure and algorithmic thinking with python]
Sample chapters [data structure and algorithmic thinking with python]
 
Lecture-05-DSA
Lecture-05-DSALecture-05-DSA
Lecture-05-DSA
 

Ähnlich wie Lecture 9 - DSA - Python Data Structures

Lect01 120922175045-phpapp01
Lect01 120922175045-phpapp01Lect01 120922175045-phpapp01
Lect01 120922175045-phpapp01Abdo ELhais
 
Rob peglar introduction_analytics _big data_hadoop
Rob peglar introduction_analytics _big data_hadoopRob peglar introduction_analytics _big data_hadoop
Rob peglar introduction_analytics _big data_hadoopGhassan Al-Yafie
 
Building Data Ecosystems for Accelerated Discovery
Building Data Ecosystems for Accelerated DiscoveryBuilding Data Ecosystems for Accelerated Discovery
Building Data Ecosystems for Accelerated Discoveryadamkraut
 
CRDC-H Draft Model Presentation to Nodes
CRDC-H Draft Model Presentation to NodesCRDC-H Draft Model Presentation to Nodes
CRDC-H Draft Model Presentation to NodesNicole Vasilevsky
 
Worldranking universities final documentation
Worldranking universities final documentationWorldranking universities final documentation
Worldranking universities final documentationBhadra Gowdra
 
Makine Öğrenmesi, Yapay Zeka ve Veri Bilimi Süreçlerinin Otomatikleştirilmesi...
Makine Öğrenmesi, Yapay Zeka ve Veri Bilimi Süreçlerinin Otomatikleştirilmesi...Makine Öğrenmesi, Yapay Zeka ve Veri Bilimi Süreçlerinin Otomatikleştirilmesi...
Makine Öğrenmesi, Yapay Zeka ve Veri Bilimi Süreçlerinin Otomatikleştirilmesi...Ali Alkan
 
Crossing the Analytics Chasm and Getting the Models You Developed Deployed
Crossing the Analytics Chasm and Getting the Models You Developed DeployedCrossing the Analytics Chasm and Getting the Models You Developed Deployed
Crossing the Analytics Chasm and Getting the Models You Developed DeployedRobert Grossman
 
00 ai-one - overview content analytics
00 ai-one -  overview  content analytics00 ai-one -  overview  content analytics
00 ai-one - overview content analyticsdiggelmann
 
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...Daniel Zivkovic
 
All data accessible to all my organization - Presentation at OW2con'19, June...
 All data accessible to all my organization - Presentation at OW2con'19, June... All data accessible to all my organization - Presentation at OW2con'19, June...
All data accessible to all my organization - Presentation at OW2con'19, June...OW2
 
How Cloud is Affecting Data Scientists
How Cloud is Affecting Data Scientists How Cloud is Affecting Data Scientists
How Cloud is Affecting Data Scientists CCG
 
Simplified Machine Learning, Text, and Graph Analytics with Pivotal Greenplum
Simplified Machine Learning, Text, and Graph Analytics with Pivotal GreenplumSimplified Machine Learning, Text, and Graph Analytics with Pivotal Greenplum
Simplified Machine Learning, Text, and Graph Analytics with Pivotal GreenplumVMware Tanzu
 

Ähnlich wie Lecture 9 - DSA - Python Data Structures (20)

Lect01 120922175045-phpapp01
Lect01 120922175045-phpapp01Lect01 120922175045-phpapp01
Lect01 120922175045-phpapp01
 
Lecture 02 - DSA
Lecture 02 - DSALecture 02 - DSA
Lecture 02 - DSA
 
DSA-2012-Lect00
DSA-2012-Lect00DSA-2012-Lect00
DSA-2012-Lect00
 
Rob peglar introduction_analytics _big data_hadoop
Rob peglar introduction_analytics _big data_hadoopRob peglar introduction_analytics _big data_hadoop
Rob peglar introduction_analytics _big data_hadoop
 
Building Data Ecosystems for Accelerated Discovery
Building Data Ecosystems for Accelerated DiscoveryBuilding Data Ecosystems for Accelerated Discovery
Building Data Ecosystems for Accelerated Discovery
 
Duplicacy of Records
Duplicacy of RecordsDuplicacy of Records
Duplicacy of Records
 
CRDC-H Draft Model Presentation to Nodes
CRDC-H Draft Model Presentation to NodesCRDC-H Draft Model Presentation to Nodes
CRDC-H Draft Model Presentation to Nodes
 
ODSC and iRODS
ODSC and iRODSODSC and iRODS
ODSC and iRODS
 
Worldranking universities final documentation
Worldranking universities final documentationWorldranking universities final documentation
Worldranking universities final documentation
 
Big data analysis concepts and references
Big data analysis concepts and referencesBig data analysis concepts and references
Big data analysis concepts and references
 
Makine Öğrenmesi, Yapay Zeka ve Veri Bilimi Süreçlerinin Otomatikleştirilmesi...
Makine Öğrenmesi, Yapay Zeka ve Veri Bilimi Süreçlerinin Otomatikleştirilmesi...Makine Öğrenmesi, Yapay Zeka ve Veri Bilimi Süreçlerinin Otomatikleştirilmesi...
Makine Öğrenmesi, Yapay Zeka ve Veri Bilimi Süreçlerinin Otomatikleştirilmesi...
 
Crossing the Analytics Chasm and Getting the Models You Developed Deployed
Crossing the Analytics Chasm and Getting the Models You Developed DeployedCrossing the Analytics Chasm and Getting the Models You Developed Deployed
Crossing the Analytics Chasm and Getting the Models You Developed Deployed
 
00 ai-one - overview content analytics
00 ai-one -  overview  content analytics00 ai-one -  overview  content analytics
00 ai-one - overview content analytics
 
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
Canadian Experts Discuss Modern Data Stacks and Cloud Computing for 5 Years o...
 
All data accessible to all my organization - Presentation at OW2con'19, June...
 All data accessible to all my organization - Presentation at OW2con'19, June... All data accessible to all my organization - Presentation at OW2con'19, June...
All data accessible to all my organization - Presentation at OW2con'19, June...
 
Big Data Analytics
Big Data AnalyticsBig Data Analytics
Big Data Analytics
 
Bigdataanalytics
BigdataanalyticsBigdataanalytics
Bigdataanalytics
 
How Cloud is Affecting Data Scientists
How Cloud is Affecting Data Scientists How Cloud is Affecting Data Scientists
How Cloud is Affecting Data Scientists
 
DSA - Lecture 03
DSA - Lecture 03DSA - Lecture 03
DSA - Lecture 03
 
Simplified Machine Learning, Text, and Graph Analytics with Pivotal Greenplum
Simplified Machine Learning, Text, and Graph Analytics with Pivotal GreenplumSimplified Machine Learning, Text, and Graph Analytics with Pivotal Greenplum
Simplified Machine Learning, Text, and Graph Analytics with Pivotal Greenplum
 

Mehr von Haitham El-Ghareeb (20)

مختصر وحدة التعلم الذاتي 2015
مختصر وحدة التعلم الذاتي 2015مختصر وحدة التعلم الذاتي 2015
مختصر وحدة التعلم الذاتي 2015
 
وحدة التعلم الذاتي 2015
وحدة التعلم الذاتي 2015وحدة التعلم الذاتي 2015
وحدة التعلم الذاتي 2015
 
NoSQL Databases, Not just a Buzzword
NoSQL Databases, Not just a Buzzword NoSQL Databases, Not just a Buzzword
NoSQL Databases, Not just a Buzzword
 
EMC Academic Alliance Presentation
EMC Academic Alliance PresentationEMC Academic Alliance Presentation
EMC Academic Alliance Presentation
 
DSA - 2012 - Conclusion
DSA - 2012 - ConclusionDSA - 2012 - Conclusion
DSA - 2012 - Conclusion
 
Data Structures - Lecture 8 - Study Notes
Data Structures - Lecture 8 - Study NotesData Structures - Lecture 8 - Study Notes
Data Structures - Lecture 8 - Study Notes
 
Lect07
Lect07Lect07
Lect07
 
Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic Sorting
 
LectureNotes-06-DSA
LectureNotes-06-DSALectureNotes-06-DSA
LectureNotes-06-DSA
 
LectureNotes-05-DSA
LectureNotes-05-DSALectureNotes-05-DSA
LectureNotes-05-DSA
 
LectureNotes-04-DSA
LectureNotes-04-DSALectureNotes-04-DSA
LectureNotes-04-DSA
 
LectureNotes-03-DSA
LectureNotes-03-DSALectureNotes-03-DSA
LectureNotes-03-DSA
 
LectureNotes-02-DSA
LectureNotes-02-DSALectureNotes-02-DSA
LectureNotes-02-DSA
 
LectureNotes-01-DSA
LectureNotes-01-DSALectureNotes-01-DSA
LectureNotes-01-DSA
 
Ph.D. Registeration seminar
Ph.D. Registeration seminarPh.D. Registeration seminar
Ph.D. Registeration seminar
 
Lecture 01 - Research Methods
Lecture 01 - Research MethodsLecture 01 - Research Methods
Lecture 01 - Research Methods
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Mozilla B2G
Mozilla B2GMozilla B2G
Mozilla B2G
 
Cisco ios-cont
Cisco ios-contCisco ios-cont
Cisco ios-cont
 

Kürzlich hochgeladen

Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 

Kürzlich hochgeladen (20)

Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 

Lecture 9 - DSA - Python Data Structures

  • 1. Data Structures in Python Crash Course Dr.Haitham A. El-Ghareeb Information Systems Department Faculty of Computers and Information Sciences Mansoura University helghareeb@gmail.com December 9, 2012 Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 1 / 61
  • 2. Agenda   •  Whe*ng  Your  Appe0te   •  Using  Python  Interpreter   •  Informal  Introduc0on  to  Python   •  More  Control  Flows   •  Data  Structures   •  Modules   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 2 / 61
  • 3. Python   •  Easy  to  learn,  powerful  programming   language.   •  Has  efficient  high-­‐level  data  structures  and  a   simple  but  effec0ve  approach  to  object-­‐ oriented  programming.   –  elegant  syntax     –  dynamic  typing   –  interpreted  nature   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 3 / 61
  • 4. Python   •  Simpler  to  use   •  Available  on  Windows,  Mac  OS  X,  and  Unix   •  Help  you  get  the  job  done  more  quickly   •  Split  your  program  into  modules  that  can  be  reused   •  Python  is  an  interpreted  language:   –  Save  you  considerable  0me  during  program   development  because  no  compila0on  and  linking   is  necessary.     –  Interpreter  can  be  used  interac0vely   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 4 / 61
  • 5. Python   •  Python  is  extensible:  if  you  know  how  to   program  in  C  it  is  easy  to  add  a  new  built-­‐in   func0on  or  module  to  the  interpreter,   •  Named  aSer  the  BBC  show  “Monty  Python’s   Flying  Circus”  and  has  nothing  to  do  with   rep0les.   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 5 / 61
  • 6. Using  the  Python  Interpreter   •  Python  interpreter  is  usually  installed  as  /usr/ local/bin/python   •  Invoking  the  Interpreter   –  A  second  way  of  star0ng  the  interpreter  is  python   -­‐c  command  [arg]  ...,  which  executes  the   statement(s)  in  command   –  Some  Python  modules  are  also  useful  as  scripts.   These  can  be  invoked  using  python  -­‐m  module   [arg]  ...,  which  executes  the  source  file  for  module   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 6 / 61
  • 7. Using  Python  Interpreter   •  Argument  Passing   •  Interac0ve  Mode   •  Error  Handling   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 7 / 61
  • 8. Executable  Python  Scripts   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 8 / 61
  • 9. Source  Code  Encoding   •  It  is  possible  to  use  encodings  different  than   ASCII  in  Python  source  files.     •  The  best  way  to  do  it  is  to  put  one  more   special  comment  line  right  aSer  the  #!  line  to   define  the  source  file  encoding:   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 9 / 61
  • 10. Informal  Introduc0on   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 10 / 61
  • 11. Using  Python  as  a  Calculator   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 11 / 61
  • 12. Numbers   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 12 / 61
  • 13. Strings   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 13 / 61
  • 14. Strings   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 14 / 61
  • 15. String  Concatena0on   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 15 / 61
  • 16. String  Indexing   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 16 / 61
  • 17. String  Slicing   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 17 / 61
  • 18. Strings  are  Immutable!   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 18 / 61
  • 19. Indices  May  be  Nega0ve   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 19 / 61
  • 20. How  Come?!   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 20 / 61
  • 21. Lists   •  compound  data  type   •  used  to  group  together  other  values     •  The  most  versa0le   •  can  be  wricen  as  a  list  of  comma-­‐separated   values  (items)  between  square  brackets.     •  List  items  need  not  all  have  the  same  type.   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 21 / 61
  • 22. Shallow  Copy   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 22 / 61
  • 23. First  Steps  toward  Programming   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 23 / 61
  • 24. More  Control  Flow  Tools   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 24 / 61
  • 25. If  Statement   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 25 / 61
  • 26. For  Statement   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 26 / 61
  • 27. For  Statement  with  Shallow  Copy   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 27 / 61
  • 28. Range  Func0on   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 28 / 61
  • 29. Break,  Con0nue,  Else   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 29 / 61
  • 30. Pass   •  Does  Nothing!   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 30 / 61
  • 31. Func0ons   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 31 / 61
  • 32. Return  Statement     Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 32 / 61
  • 33. Default  Argument  Value   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 33 / 61
  • 34. Documenta0on  String   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 34 / 61
  • 35. Coding  Style  -­‐  PEP8   •  Use  4-­‐space  indenta0on,  and  no  tabs.   •  4  spaces  are  a  good  compromise  between  small   indenta0on  (allows  greater  nes0ng  depth)  and  large   indenta0on  (easier  to  read).  Tabs  introduce  confusion,   and  are  best  leS  out.   •  Wrap  lines  so  that  they  don’t  exceed  79  characters.   •  This  helps  users  with  small  displays  and  makes  it   possible  to  have  several  code  files  side-­‐by-­‐side  on   larger  displays.   •  Use  blank  lines  to  separate  func0ons  and  classes,  and   larger  blocks  of  code  inside  func0ons.   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 35 / 61
  • 36. Coding  Style  -­‐  PEP8   •  When  possible,  put  comments  on  a  line  of  their  own.   •  Use  docstrings.   •  Use  spaces  around  operators  and  aSer  commas,  but  not   directly  inside  bracke0ng  constructs:  a  =  f(1,  2)  +  g(3,  4).   •  Name  your  classes  and  func0ons  consistently;  the   conven0on  is  to  use  CamelCase  for  classes  and   lower_case_with_underscores  for  func0ons  and  methods.   Always  use  self  as  the  name  for  the  first  method  argument.   •  Don’t  use  fancy  encodings  if  your  code  is  meant  to  be  used   in  interna0onal  environments.  Plain  ASCII  works  best  in  any   case.   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 36 / 61
  • 37. Data  Structures  -­‐  Lists   •  list.append(x)  Add  an  item  to  the  end  of  the  list.   •  list.extend(L)  Extend  the  list  by  appending  all  the   items  in  the  given  list.   •  list.insert(i,  x)  Insert  an  item  at  a  given  posi0on.   The  first  argument  is  the  index  of  the  element   before  which  to  insert,  so  a.insert(0,  x)  inserts  at   the  front  of  the  list,  and  a.insert(len(a),  x)  is   equivalent  to  a.append(x).   •  list.remove(x)  Remove  the  first  item  from  the  list   whose  value  is  x.  It  is  an  error  if  there  is  no  such   item.   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 37 / 61
  • 38. Data  Structures  -­‐  Lists   •  list.pop([i])  Remove  the  item  at  the  given  posi0on  in   the  list,  and  return  it.  If  no  index  is  specified,  a.pop()   removes  and  returns  the  last  item  in  the  list.     •  list.index(x)  Return  the  index  in  the  list  of  the  first  item   whose  value  is  x.  It  is  an  error  if  there  is  no  such  item.   •  list.count(x)  Return  the  number  of  0mes  x  appears  in   the  list.   •  list.sort()  Sort  the  items  of  the  list,  in  place.   •  list.reverse()  Reverse  the  elements  of  the  list,  in  place.   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 38 / 61
  • 39. Lists  Example   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 39 / 61
  • 40. Using  Lists  as  Stack   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 40 / 61
  • 41. Using  List  as  a  Queue   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 41 / 61
  • 42. Func0onal  Programming  Tools   •  There  are  three  built-­‐in  func0ons  that  are  very   useful  when  used  with  lists:  filter(),  map(),  and   reduce().   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 42 / 61
  • 43. Filter()   •  filter(func0on,  sequence)  returns  a  sequence   consis0ng  of  those  items  from  the  sequence   for  which  func0on(item)  is  true.     •  If  sequence  is  a  string  or  tuple,  the  result  will   be  of  the  same  type;  otherwise,  it  is  always  a   list.     •  For  example,  to  compute  a  sequence  of   numbers  not  divisible  by  2  and  3:   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 43 / 61
  • 44. Filter()   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 44 / 61
  • 45. Map()   •  map(func0on,  sequence)  calls  func0on(item)   for  each  of  the  sequence’s  items  and  returns  a   list  of  the  return  values.     •  For  example,  to  compute  some  cubes:   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 45 / 61
  • 46. Map()   •  More  than  one  sequence  may  be  passed;  the   func0on  must  then  have  as  many  arguments   as  there  are  sequences  and  is  called  with  the   corresponding  item  from  each  sequence  (or   None  if  some  sequence  is  shorter  than   another).  For  example:   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 46 / 61
  • 47. Reduce()   •  reduce(func0on,  sequence)  returns  a  single   value  constructed  by  calling  the  binary   func0on  func2on  on  the  first  two  items  of  the   sequence,  then  on  the  result  and  the  next   item,  and  so  on.     •  For  example,  to  compute  the  sum  of  the   numbers  1  through  10:   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 47 / 61
  • 48. Tuples  and  Sequences   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 48 / 61
  • 49. Comma  at  the  end!   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 49 / 61
  • 50. Sets   •  A  set  is  an  unordered  collec0on  with  no   duplicate  elements.     •  Basic  uses  include  membership  tes0ng  and   elimina0ng  duplicate  entries.     •  Set  objects  also  support  mathema0cal   opera0ons  like  union,  intersec0on,  difference,   and  symmetric  difference.   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 50 / 61
  • 51. Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 51 / 61
  • 52. Dic0onaries   •  Dic0onaries  are  some0mes  found  in  other   languages  as  “associa0ve  memories”  or   “associa0ve  arrays”.     •  Unlike  sequences,  which  are  indexed  by  a  range   of  numbers,  dic0onaries  are  indexed  by  keys,   which  can  be  any  immutable  type;  strings  and   numbers  can  always  be  keys.     •  Tuples  can  be  used  as  keys  if  they  contain  only   strings,  numbers,  or  tuples;  if  a  tuple  contains   any  mutable  object  either  directly  or  indirectly,  it   cannot  be  used  as  a  key.     Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 52 / 61
  • 53. Dic0onaries   •  You  can’t  use  lists  as  keys,  since  lists  can  be  modified  in   place  using  index  assignments,  slice  assignments,  or   methods  like  append()  and  extend().   •  It  is  best  to  think  of  a  dic0onary  as  an  unordered  set  of   key:  value  pairs,  with  the  requirement  that  the  keys   are  unique  (within  one  dic0onary).     •  A  pair  of  braces  creates  an  empty  dic0onary:  {}.  Placing   a  comma-­‐separated  list  of  key:value  pairs  within  the   braces  adds  ini0al  key:value  pairs  to  the  dic0onary;   this  is  also  the  way  dic0onaries  are  wricen  on  output.   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 53 / 61
  • 54. Dic0onaries   •  The  main  opera0ons  on  a  dic0onary  are  storing  a  value   with  some  key  and  extrac0ng  the  value  given  the  key.   •  It  is  also  possible  to  delete  a  key:value  pair  with  del.  If   you  store  using  a  key  that  is  already  in  use,  the  old   value  associated  with  that  key  is  forgocen.  It  is  an   error  to  extract  a  value  using  a  non-­‐existent  key.   •  The  keys()  method  of  a  dic0onary  object  returns  a  list   of  all  the  keys  used  in  the  dic0onary,  in  arbitrary  order   (if  you  want  it  sorted,  just  apply  the  sorted()  func0on   to  it).     •  To  check  whether  a  single  key  is  in  the  dic0onary,  use   the  in  keyword.   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 54 / 61
  • 55. Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 55 / 61
  • 56. Dict()  Constructor   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 56 / 61
  • 57. Looping  Techniques   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 57 / 61
  • 58. Looping  over  Two  Sequences   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 58 / 61
  • 59. Loop  in  Reverse   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 59 / 61
  • 60. More  on  Condi0ons   •  Include  and,  or   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 60 / 61
  • 61. Comparing  Objects  of  Different  Types   Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 December 9, 2012 61 / 61