首页新闻找找看学习计划

python使用列表名

0
悬赏园豆:10 [已解决问题] 解决于 2017-07-17 22:48

def greeting(userlist):
for name in userlist:
print("welcome here " + name)
def move(list1, list2):
while list1:
for user in list1:
current_user = list1.pop()
a = "list1"
b = "list2"
print(current_user + " is moved from " + a + " to " + b)                 ###########
unconfirmed_users = ['xxx', 'yyy', 'zzz']
confirmed_users = []
move(unconfirmed_users, confirmed_users)
greeting(confirmed_users)

 

原本想在第十行(已用###标记)print出这样的效果

“xxx is moved from unconfirmed_users to confirmed_users".

然而出来的效果是这样的

xxx is moved from list1 to list2

请问怎么达到我想要的效果

skrrr的主页 skrrr | 初学一级 | 园豆:110
提问于:2017-07-17 17:30
< >
分享
最佳答案
1
def greeting(userlist):
    for name in userlist:
        print("welcome here " + name)


def move(list1, list2):
    while list2:
        for user in list1:
            current_user = list1.pop()
            a = list2[0]
            b = list2[1]
            print(
                current_user + " is moved from " + a + " to " + b)  ###########


unconfirmed_users = ['xxx', 'yyy', 'zzz']
confirmed_users = ['unconfirmed_users', 'confirmed_users']
move(unconfirmed_users, confirmed_users)
greeting(confirmed_users)

收获园豆:10
梦里寻人 | 专家六级 |园豆:11377 | 2017-07-17 17:54

可能有一点曲解我的意思了,不过我明白怎么解决了,谢谢

skrrr | 园豆:110 (初学一级) | 2017-07-17 18:24
其他回答(1)
0

你的

a = "list1"
b = "list2"

出来的肯定是xxx is moved from list1 to list2

你要“xxx is moved from unconfirmed_users to confirmed_users".

就把8、9行改成

a = "unconfirmed_users"
b = "confirmed_users

 

谁说不是呢

兰冰点点 | 园豆:394 (菜鸟二级) | 2017-07-17 17:37

但我觉得你想要的不应该是这个

支持(0) 反对(0) 兰冰点点 | 园豆:394 (菜鸟二级) | 2017-07-17 17:38

@兰冰点点: 嗯...如果我想多次用这个函数的话这样就不可以了

支持(0) 反对(0) skrrr | 园豆:110 (初学一级) | 2017-07-17 17:41

@skrrr: 所以,请通俗的描述你要干嘛

支持(0) 反对(0) 兰冰点点 | 园豆:394 (菜鸟二级) | 2017-07-17 17:42

@兰冰点点: move(unconfirmed users, confirmed users)

move(beautiful users, ugly users)

如何让这个函数既能打出xxx is moved from unconfirmed users to confirmed users

又能打出yyy is moved from beautiful users to ugly users

支持(0) 反对(0) skrrr | 园豆:110 (初学一级) | 2017-07-17 17:47

@skrrr: 你传参数啊,传什么就打印什么

没参数也有个判断逻辑吧,不然你怎么定义什么情况输出什么打印

支持(0) 反对(0) 兰冰点点 | 园豆:394 (菜鸟二级) | 2017-07-17 17:49

@兰冰点点: 不好意思大概明白了,谢谢

支持(0) 反对(0) skrrr | 园豆:110 (初学一级) | 2017-07-17 17:54

@兰冰点点: 真不好意思啊

我只能做到用input

def greeting(userlist):
for name in userlist:
print("welcome here " + name)
def move(list1, list2):
a = input("old list\n")
b = input("new list\n")
while list1:
current_user = list1.pop()
print(current_user + " is moved from " + a + " to " + b)
unconfirmed_users = ['xxx', 'yyy', 'zzz']
confirmed_users = []
move(unconfirmed_users, confirmed_users)
greeting(confirmed_users)

但不是我想要的效果,能否省去手动输入这部分,直接在move(unconfirmed_users,confirmed_users)这里就直接将两个列表名储存起来

支持(0) 反对(0) skrrr | 园豆:110 (初学一级) | 2017-07-17 18:03

@兰冰点点: 

def greeting(userlist):
    for name in userlist:
    print("welcome here " + name)
def move(list1, list2):
    a = input("old list\n")
    b = input("new list\n")
    while list1:
        current_user = list1.pop()
        print(current_user + " is moved from " + a + " to " + b)
unconfirmed_users = ['xxx', 'yyy', 'zzz']
confirmed_users = []
move(unconfirmed_users, confirmed_users)
greeting(confirmed_users)

支持(0) 反对(0) skrrr | 园豆:110 (初学一级) | 2017-07-17 18:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册