@@ -311,7 +311,7 @@ odds: [1, 3, 5, 7]
311311> Use a for-loop to convert the string "hello" into a list of letters:
312312>
313313> ~~~
314- > ["h", "e", "l", "l", "o" ]
314+ > ['h', 'e', 'l', 'l', 'o' ]
315315> ~~~
316316> {: .language-python}
317317>
@@ -325,7 +325,7 @@ odds: [1, 3, 5, 7]
325325> > ## Solution
326326> > ~~~
327327> > my_list = []
328- > > for char in " hello" :
328+ > > for char in ' hello' :
329329> > my_list.append(char)
330330> > print(my_list)
331331> > ~~~
@@ -338,26 +338,26 @@ similar to how we accessed ranges of positions in a NumPy array.
338338This is commonly referred to as "slicing" the list/string.
339339
340340~~~
341- binomial_name = " Drosophila melanogaster"
341+ binomial_name = ' Drosophila melanogaster'
342342group = binomial_name[ 0:10]
343- print(" group:" , group)
343+ print(' group:' , group)
344344
345345species = binomial_name[ 11:23]
346- print(" species:" , species)
346+ print(' species:' , species)
347347
348- chromosomes = [ "X", "Y", "2", "3", "4" ]
348+ chromosomes = [ 'X', 'Y', '2', '3', '4' ]
349349autosomes = chromosomes[ 2:5]
350- print(" autosomes:" , autosomes)
350+ print(' autosomes:' , autosomes)
351351
352352last = chromosomes[ -1]
353- print(" last:" , last)
353+ print(' last:' , last)
354354~~~
355355{: .language-python}
356356
357357~~~
358358group: Drosophila
359359species: melanogaster
360- autosomes: [ "2", "3", "4" ]
360+ autosomes: [ '2', '3', '4' ]
361361last: 4
362362~~~
363363{: .output}
@@ -367,18 +367,18 @@ last: 4
367367> Use slicing to access only the last four characters of a string or entries of a list.
368368>
369369> ~~~
370- > string_for_slicing = " Observation date: 02-Feb-2013"
371- > list_for_slicing = [[" fluorine", "F" ],
372- > [" chlorine", "Cl" ],
373- > [" bromine", "Br" ],
374- > [" iodine", "I" ],
375- > [" astatine", "At" ]]
370+ > string_for_slicing = ' Observation date: 02-Feb-2013'
371+ > list_for_slicing = [[' fluorine', 'F' ],
372+ > [' chlorine', 'Cl' ],
373+ > [' bromine', 'Br' ],
374+ > [' iodine', 'I' ],
375+ > [' astatine', 'At' ]]
376376> ~~~
377377> {: .language-python}
378378>
379379> ~~~
380- > " 2013"
381- > [[" chlorine", "Cl" ], [" bromine", "Br" ], [" iodine", "I" ], [" astatine", "At" ]]
380+ > ' 2013'
381+ > [[' chlorine', 'Cl' ], [' bromine', 'Br' ], [' iodine', 'I' ], [' astatine', 'At' ]]
382382> ~~~
383383> {: .output}
384384>
@@ -414,7 +414,7 @@ last: 4
414414> ~~~
415415> primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
416416> subset = primes[0:12:3]
417- > print(" subset" , subset)
417+ > print(' subset' , subset)
418418> ~~~
419419> {: .language-python}
420420>
@@ -431,7 +431,7 @@ last: 4
431431> ~~~
432432> primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
433433> subset = primes[2:12:3]
434- > print(" subset" , subset)
434+ > print(' subset' , subset)
435435> ~~~
436436> {: .language-python}
437437>
@@ -483,11 +483,11 @@ If you want to take a slice from the beginning of a sequence, you can omit the f
483483range:
484484
485485~~~
486- date = " Monday 4 January 2016"
486+ date = ' Monday 4 January 2016'
487487day = date[ 0:6]
488- print(" Using 0 to begin range:" , day)
488+ print(' Using 0 to begin range:' , day)
489489day = date[ :6]
490- print(" Omitting beginning index:" , day)
490+ print(' Omitting beginning index:' , day)
491491~~~
492492{: .language-python}
493493
@@ -501,20 +501,20 @@ And similarly, you can omit the ending index in the range to take a slice to the
501501sequence:
502502
503503~~~
504- months = [ " jan", " feb", " mar", " apr", " may", " jun", " jul", " aug", " sep", " oct", " nov", " dec" ]
504+ months = [ ' jan', ' feb', ' mar', ' apr', ' may', ' jun', ' jul', ' aug', ' sep', ' oct', ' nov', ' dec' ]
505505sond = months[ 8:12]
506- print(" With known last position:" , sond)
506+ print(' With known last position:' , sond)
507507sond = months[ 8: len (months)]
508- print(" Using len() to get last entry:" , sond)
508+ print(' Using len() to get last entry:' , sond)
509509sond = months[ 8:]
510- print(" Omitting ending index:" , sond)
510+ print(' Omitting ending index:' , sond)
511511~~~
512512{: .language-python}
513513
514514~~~
515- With known last position: [ " sep", " oct", " nov", " dec" ]
516- Using len() to get last entry: [ " sep", " oct", " nov", " dec" ]
517- Omitting ending index: [ " sep", " oct", " nov", " dec" ]
515+ With known last position: [ ' sep', ' oct', ' nov', ' dec' ]
516+ Using len() to get last entry: [ ' sep', ' oct', ' nov', ' dec' ]
517+ Omitting ending index: [ ' sep', ' oct', ' nov', ' dec' ]
518518~~~
519519{: .output}
520520
0 commit comments