Responses for exercises in Exercism.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.7 KiB

Hints

General

There's four activities in the assignment, each with a set of text or words to work with.

1. Add a prefix to a word

  • Small strings can be concatenated with the + operator.

2. Add prefixes to word groups

  • Believe it or not, <str>.join() is all you need.
  • Like <str>.split(), <str>.join() can take an arbitrary-length string, made up of any unicode code points.

3. Remove a suffix from a word

  • Strings can be both indexed and sliced from either the left (starting at 0) or the right (starting at -1).
  • If you want the last code point of an arbitrary-length string, you can use [-1].
  • The last three letters in a string can be "sliced off" using a negative index. e.g. 'beautiful'[:-3] == 'beauti'

4. Extract and transform a word

  • Using <str>.split() returns a list of strings broken on white space.
  • lists are sequences, and can be indexed.
  • <str>.split() can be direcly indexed. e.g. 'Exercism rocks!'.split()[0] == 'Exercism'
  • Be careful of punctuation! Periods can be removed via slice: 'dark.'[:-1] == 'dark'