1 / 9

computer science

CSCI 1001. overview of. computer science. PYTHON V. ages = [20, 18, 17, 26]. 17 in ages. ages.index(17). sum(ages ). range(0,10,2). ‘ abc ’ in ‘ abcdefg ’. ‘how are you’[4:7]. s = ‘Mr. Spock’. s[0:2] = ‘Dr’ #Won’t work. ‘do re mi fa so’.find(‘mi ’).

dinesh
Télécharger la présentation

computer science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 1001 overview of computer science PYTHON V

  2. ages = [20, 18, 17, 26] 17 in ages ages.index(17) sum(ages) range(0,10,2)

  3. ‘abc’ in ‘abcdefg’ ‘how are you’[4:7] s = ‘Mr. Spock’ s[0:2] = ‘Dr’ #Won’t work ‘do re mi faso’.find(‘mi’) for s in ‘i can hazcheez’: print s.upper(),

  4. d = {} # empty dictionary d = {‘nishi’:4, ‘lnp’:1} d[‘nishi’] d[‘neshek’] # KeyError ‘neshek’ in d d[‘neshek’] = 1 len(d)

  5. d = {‘nishi’:4, ‘lnp’:1} d.keys() d.values() d.items() del d[‘lnp’] # in St. Louis dict.fromkeys([1,2,3],’a’)

  6. def common(alice, bob): cs = [] for a in alice: if a in bob: cs.append(a) return cs def common2(as, bs): cs = [] d = dict.fromkeys(bs,True) for a in as: if a in d: cs.append(a) return cs

  7. fileName = raw_input(“file name: ") f = open(fileName) sum = 0 numLines = 0 for currentLine in f: sum = sum + len(currentLine) numLines = numLines + 1 print "Number of lines: ", numLines if numLines != 0: print "Avg length:", sum/numLines

  8. import urllib url = raw_input(“input the url: ") u = urllib.urlopen(url) sum = 0 numLines = 0 for currentLine in u: sum = sum + len(currentLine) numLines = numLines + 1 print "Number of lines: ", numLines if numLines != 0: print "Average line length: ", sum/numLines

  9. http://cs1001.us/ Please read Sections 3.3 and 3.4 for Wednesday

More Related