isds2020 icon indicating copy to clipboard operation
isds2020 copied to clipboard

regarding _0.5.0

Open SiriSVC opened this issue 5 years ago • 4 comments
trafficstars

The assert line raises an error, when I run the following code:

chars = ["en", "da"] answer_050 = change_url(chars) print(answer_050)

I am not sure what the error is, but I am sure my code is wrong since the output doesn’t come out as a list with the url in the languages contained in the list.

Do you know how to fix it? Thanks :)

SiriSVC avatar Aug 05 '20 11:08 SiriSVC

Hi @SiriSVC , you will have to loop over the list chars, apply the change_url() function to each string contained in chars and append each processed string to the list answer_050. In your current code you apply the function to the whole list which is not what you want :)

jsr-p avatar Aug 05 '20 18:08 jsr-p

Thanks Jonas :)

However I still cannot get it right... I receive TypeError: 'str' object is not callable to the following code:

chars = ["en", "da"] # initialize list outside the main loop

for x in (chars): #loop over the list chars change_url = change_url(x) #apply the change_url() function to each string contained in chars answer_50.append(change_url(x)) #and append each processed string to the list answer_050 print(answer_50)

:)

SiriSVC avatar Aug 06 '20 10:08 SiriSVC

Hi @SiriSVC, you are storing the processed string in a variable with the same name as the function in this line: change_url = change_url(x) #apply the change_url() function to each string contained in chars

As such, when you write answer_50.append(change_url(x))you are trying to use the string that you just stored in change_url as a function, but the variable is not pointing to a function anymore but a string and therefore it throws the TypeError.

Store the processed string in a variable named something different, e.g. processed_string. Then you can append the variable processed_string to the list and everything should be fine :)

jsr-p avatar Aug 06 '20 11:08 jsr-p

ahh yes :) THANKS! - now it works (at least the output does).

SiriSVC avatar Aug 06 '20 11:08 SiriSVC