MCQs: Python text processing

Feb 6, 2014 • Likit Preeyanon

Novices vs Practitioners

Which of the following command will return “GL012″?

s = ‘chrZt34500t45000tgeneid=GL012;transcriptID=0001;symbol=XVF’

  1. s.split(‘=’)[2].split(‘;’)[0]
  2. s.replace(‘=’, ‘t’).split()[3].split(‘;’)[0]
  3. s.split(‘t’)[-1].split(‘;’)[0].split(‘=’)[-1]
  4. s.replace(‘;’, ‘t’, 1).split()[3].split(‘=’)

Assessment

What is the output of the following command:
‘hello,world’.split(‘,’)[1].find(‘h’)

  1. -1
  2. 1
  3. ValueError: substring not found

Exercise

Fill in a right method for each output.

s = ‘John,Michigan,Engineern’

s.___(‘,’) **—>** [‘John’, ‘Michigan’, ‘Engineern’]
s.
_\_(‘____’, ‘__’) **—>** ‘John,MI,Engineern’
s._
() **—>** ‘jOHN,mICHIGAN,eNGINEERn’
s._
__ (‘Engine’) —> 14
s._
(‘OHIO’) **—>** ValueError: substring not found
s._
_(‘OHIO’) —> -1