Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 2 Review Spring 2006: String Fun


What do source[:loc] and source[loc + 1:] mean/do?
When referencing a specific location of a string, you can access an individual element by putting the loction inside the []'s. You can define a range as well by separating the beginning and ending loctions with a colon. If there isn't a beginning location defined (example being the first part) and if there isn't an ending location (example being the second part), what do you think happens? -poof #10

Yeah, I know what the thing does with examples such as [12:44], but with things like loc and blanks (nothing specified), I'm not sure. Does is start at the begining of just do the whole thing?
Not the whole thing. Just up to where? And what about if the colon comes second? -poof #10

In thingamabob, is the [:loc] saying that it will get rid of all vowels until it hits something that makes loc=1, like an i?
Not quite... It is saying start at the beginning, and go until you find the one vowel you are looking for at that point in the for loop. Then what does it do? Liz Helms

Helpful comment: Think of s[:x] as shorthand for s[0:x] (i.e. the part of s from the start to x) and s[x:] as a shorthand for [x:len(s)] (i.e. the rest of s from x to the end). For that matter, s[:] is an obscure way of saying s. Colin Potts
Curmudgeonly comment: There is a slide on this confusing (in my opinion) Python notation in the lecture on text processing. If you don't recognize something, then you may have either missed that lecture or zoned out for a couple of minutes. (It happens.) Check the your notes, the slides, the book, and answers to previous questions before asking a question. Colin Potts


For thingamajig, why is there a second "loc = source.find(i)" at the very end of the function? It seems to me that it doesn't do anything.


It's inside the while loop, so even though it isn't at the very end, that doesn't mean the function will stop right after that line is done. -Blake O'Hare

So does the first function only find the first respective vowel, removes it, and then moves on to the next vowel?

for the first function

source = "georgia institute of technology"

i = a
loc = 6
source = "georgi" + " instutute of technology" = "georgi institute of technology"

i=e
loc = 1
source = "g" + "orgi instutute of technology" = "gorgi institute of technology"

i=i
loc = 4
source = "gorg" + " institute of technology" = "gorg institute of technology"

i = o
loc = 1
source = "g" +"rg institute of technology" = "grg institute of technology"

"grg insitute of technology"

Is this right?

is 'geogia institute of technology' right for both functions?

 ^ you forgot the u vowel, so it should be grg institte of technology 


Do you refer back to the original source each time you go to the for loop and do the loc=source.find(i) or do you refer to the revised one? for example i got:
i    source  
a     [6]
e     [1]
i     [5]
o     [2]
u     [14]

i got different locations of the i in vowels than the previous guy because each time i referred to "georgia institute of technology" when finding the source location of (i). Is that wrong? i got the right answer "grg institte of technology" by doing it that way. 



Link to this Page