Need help with a python problem.

今天

知名会员
注册
2003-11-08
消息
1,288
荣誉分数
471
声望点数
193
Instructions
Write a function hide_inside that consumes a list, an item, and a nonnegative integer pos.

Your function should produce a new list that contains all theitems of the input list with the new item inserted in positionpos. For example,

hide_inside(["a", "b"], "cat", 1]

will produce ["a", "cat", "b"]. If pos is greater than the length of the list, the item should appear at the end of the list. For example,

hide_inside(["a", "b"], "cat", 20]

will produce ["a", "b", "cat"].
my solution is
def hide_inside(anylist,pos,item):
seq=anylist
if pos>=len(seq):
pos=len(seq)
elif pos<=0:
pos=0
item=item
seq.insert(pos,item)
return seq

Could somebody please help me with this problem
o
 
玩python的华人马公今天都回避了, 怕现了原形。lol
 
玩python的华人马公今天都回避了, 怕现了原形。lol
看来时间太晚了,小盆友卡壳几天了,希望有人能帮他一下,谢谢
 
def hide_inside(anylist,pos,item):
To
def hide_inside(anylist,item,pos):
 
Instructions
Write a function hide_inside that consumes a list, an item, and a nonnegative integer pos.

Your function should produce a new list that contains all theitems of the input list with the new item inserted in positionpos. For example,

hide_inside(["a", "b"], "cat", 1]

will produce ["a", "cat", "b"]. If pos is greater than the length of the list, the item should appear at the end of the list. For example,

hide_inside(["a", "b"], "cat", 20]

will produce ["a", "b", "cat"].
my solution is
def hide_inside(anylist,pos,item):
seq=anylist
if pos>=len(seq):
pos=len(seq)
elif pos<=0:
pos=0
item=item
seq.insert(pos,item)
return seq

Could somebody please help me with this problem
o

........... 楼主这c programmer脑袋,唉

代码:
def hide_inside(l, obj, j):
    return l[:j] + [obj] + l[j:]
 
看来时间太晚了,小盆友卡壳几天了,希望有人能帮他一下,谢谢
最好让小朋友自己上网搜索解决办法,Google,reddit,各种code 网站,既提高了娃自己的能力,又省了你的事。
 
看来时间太晚了,小盆友卡壳几天了,希望有人能帮他一下,谢谢
昨天是端午节,python是蛇,那些华人的 python马公 据说都没干活。:D
 
最好让小朋友自己上网搜索解决办法,Google,reddit,各种code 网站,既提高了娃自己的能力,又省了你的事。
好主意,谢谢
........... 楼主这c programmer脑袋,唉

代码:
def hide_inside(l, obj, j):
    return l[:j] + [obj] + l[j:]
不是我的脑袋,我不会一点编程,儿子小学4年级自学这东西,周围也没有个认识的朋友会编程,我也不懂 让他上来问问
谢谢各位的回复
 
扛不住这点压力没点厚脸皮干不了俺们这行:p:p:p
他只是爱好,暂时还早考虑面试的事情;)
上次你帮他解决的题,他很高兴,说你很厉害,谢谢
 
后退
顶部
首页 论坛
消息
我的