abjer / isds2020

Introduction to Social Data Science 2020 - a summer school course abjer.github.io/isds2020
58 stars 92 forks source link

regarding _0.5.0 #16

Open SiriSVC opened 4 years ago

SiriSVC commented 4 years ago

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 :)

jsr-p commented 4 years ago

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 :)

SiriSVC commented 4 years ago

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)

:)

jsr-p commented 4 years ago

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 :)

SiriSVC commented 4 years ago

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