Introduc)on to Programming using Python Programming Course - - PowerPoint PPT Presentation

introduc on to programming using python
SMART_READER_LITE
LIVE PREVIEW

Introduc)on to Programming using Python Programming Course - - PowerPoint PPT Presentation

Introduc)on to Programming using Python Programming Course for Biologists WC-16 David Knox and Phil Richmond Dic)onary Data Type Similar to Word


slide-1
SLIDE 1

Introduc)on ¡to ¡Programming ¡ using ¡Python ¡

Programming ¡Course ¡for ¡Biologists ¡ WC-­‑16 ¡ David ¡Knox ¡and ¡Phil ¡Richmond ¡

slide-2
SLIDE 2

Dic)onary ¡Data ¡Type ¡

  • Similar ¡to ¡Word ¡Dic)onary ¡

– Lookup ¡by ¡Word ¡ – Find ¡defini)on(s) ¡

slide-3
SLIDE 3

Dic)onary ¡is ¡a ¡Table ¡

Key ¡ Value ¡

slide-4
SLIDE 4

Dic)onary ¡is ¡a ¡Table ¡

Key ¡ Value ¡ 'EcoRI’ 'gaattc' 'BamHI’ 'ggatcc' 'HindIII’ 'aagctt' … …

slide-5
SLIDE 5

dict() ¡

  • Create ¡new ¡dic)onary ¡

¡enzymeRestrictions = dict()

  • Add ¡item ¡to ¡the ¡dic)onary ¡

enzymeRestrictions[“EcoR1”] = ‘gaattc’

  • Get ¡value ¡for ¡item ¡

seq = enzymeRestrictions[“EcoR1”]

  • Check ¡for ¡item ¡in ¡dict ¡

enzymeRestrictions.has_key(‘HindIII’)

  • Replace ¡Item ¡

enzymeRestrictions[“EcoR1”] = ‘GAATTC’

slide-6
SLIDE 6

Dic)onary ¡is ¡a ¡Table ¡

Key ¡ Value ¡ ’TATA’ 5 ’GATA’ 6 ’CATA’ 1 … …

slide-7
SLIDE 7

Dic)onary ¡is ¡a ¡Table ¡

Key ¡ Value ¡ 105387 [‘GAL10’,‘GENE’, ‘+’,’TSS’, ‘DOUBIOUS’] 105935 [‘LTR’, …] 106702 [ ‘GAL1’, ‘GENE’, …] … …

slide-8
SLIDE 8

Compare ¡Data ¡Types ¡and ¡Methods ¡

slide-9
SLIDE 9

Dic)onary ¡Methods ¡

  • Ini)aliza)on ¡of ¡dic)onary ¡ ¡

d = {‘key1’:’v1’, ‘key2’:’v2’, …}

  • Get ¡list ¡of ¡the ¡keys ¡in ¡a ¡dic)onary ¡ ¡

d.keys() - order ¡of ¡the ¡keys ¡is ¡unknown ¡

  • Get ¡a ¡list ¡of ¡the ¡values ¡in ¡a ¡dic)onary ¡

d.values()

  • Itera)on ¡through ¡the ¡dic)onary ¡

for key,value in d: print key,”:”,value

slide-10
SLIDE 10

Summary ¡WC-­‑16 ¡

  • Dic)onary ¡Data ¡Type ¡
  • Contains ¡Keys ¡and ¡Values ¡
  • Lookup ¡Table ¡ ¡
  • Look ¡by ¡key ¡
  • Key ¡is ¡unique ¡
  • Value ¡can ¡be ¡any ¡object ¡ ¡

(including ¡a ¡dic)onary) ¡