What happend to me?


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#


I have a problem. when I print each members of list which is I replaced, it works.
but when I tried to print whole list, the member I replaced isn't changed.
even I already check by printing each members of the list.

I'm from Asia, so maybe you confused what I meant.
so I comment on the line where I stuck to.

Why does this happen? Why does it not change?

Is this issue about memory structure?

I really need your help guys.


def censor(text, word):
    ary=text.split()
    for member in ary:
        if member==word:
            member="*"*len(word)
        print member    # *****\n my\n load\n
    print ary           # [hello', 'my', 'load']

censor("hello my load", "hello")


#2

is it about 'call by value' and 'call by reference'?

I change to access with index like ary[i] not just member, and it works.


#3

the drawback of using such a for loop:

for member in ary

is that member is variable which gets assigned the words in your list in order, but in each run of the loop it gets re-assigned, and after the loop it cease to exist

If you where to use range() instead, you get indexes which you can use to actually manipulate the list


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.