Little Sister's Vocabulary: make_word_groups

Hi,
I am completly lost with this exercise on strings.
I have tu add the first item of the list to the others and finally transform the list in a string using .join.
My idea is to add the prefix as you can see below, but i does not work. Furthermore the hips is not helpful at all: " Believe it or not, str.join() is all you need here"…
I’ve wroted this code thinkig it slice the list from item 2 (index 1) to the end, index 0 is the prefix:

def make_word_groups(vocab_words):

for palabra in vocab_words[1:]:
palabra = vocab_words[0] + palabra
return " :: ".join(vocab_words)

Maybe my logic is not correct I use to program in vba for excel (my job tool o.o’) but the output is the original list

Hi @jmpsuperhornet ,

A str in Python is an immutable sequence of Unicode code points.

The means that the actual string values in vocab_words cannot be changed by just reading a list item into a variable and changing that variable. For example, consider what happens in the for loop for the first item (vocab_words[1]). Let’s say that vocab_words is this:

vocab_words = ["en", "light", "joy"]

Then, palabra will have this value:

palabra = vocab_words[0] + vocab_words[1]

The value of palabra will be "enlight". However the value of vocab_words[1] will be unchanged. You will either need to create a new list of words that you can pass to join or modify the existing list. Alternatively, this can be done with list comprehension. It’s been a while since I did the python track, so I don’t remember if that topic has been mentioned yet.

thaks for your help. I could do it. As list comprehension is a topic not mentioned yet I did a new list

  lista=[vocab_words[0]]
  for palabra in vocab_words[1:]:
     lista.append(vocab_words[0] + palabra)
  return " :: ".join(lista)
1 Like