列表轮换 [英] List rotation
问题描述
大家好,
有人可以帮我解决这个问题吗?
items =(''''',''b '',''''','''')
items + 1 =(''b'',''c'',''d'',''a' ')
items + 2 =(''c'',''d'',''a'',''b'')
items + 3 =(''d'','''',''b'',''c'')
trans = 1
list =('''','''',''b'','''','''','''',''b'')
#and items = +1,列表将是;
#list =(''b'',''a'',''c' ',''b'',''a'','d'',''c'')等等。
for idx in range(len(list) ):
如果trans == [1]:
list [idx] = [???]
print l1
不要笑,我慢学习:)
谢谢,
M
Hi All,
Could someone help me out with this?
items = (''a'', ''b'', ''c'', ''d'')
items + 1 = ( ''b'', ''c'', ''d'', ''a'')
items + 2 = ( ''c'', ''d'', ''a'', ''b'')
items + 3 = ( ''d'', ''a'', ''b'', ''c'')
trans = 1
list = (''a'', ''d'', ''b'', ''a'', ''d'', ''c'', ''b'')
#and items = +1, the list would be;
#list = (''b'', ''a'', ''c'', ''b'', ''a'', ''d'', ''c'') etc..
for idx in range(len(list)):
if trans == [1]:
list[idx] = [???]
print l1
Don''t laugh, I''m a slow learner : )
Thanks,
M
推荐答案
当然应该在最后阅读打印清单
" M.克里福特" <无*** @ here.com>在消息中写道
news:cj ********** @ news8.svr.pol.co.uk ...
That should of course read print list at the end
"M. Clift" <no***@here.com> wrote in message
news:cj**********@news8.svr.pol.co.uk...
大家好,
有人可以帮我解决这个问题吗?
items =('''',''b'',''c'',''d'')
items + 1 =(''b'',''c'','d'',''a'')
项目+ 2 =(''c'',''d '','''',''b'')
项目+ 3 =(''d'',''a'',''b'',''c'')
trans = 1
list =('''','''',''b'','''','''', ''c'',''b'')
#and items = +1,列表将是;
#list =(''b'',''a' ',''c'','b'',''a'','d'',''c'')等等。
适用于范围内的idx(len( list)):
如果trans == [1]:
list [idx] = [???]
打印l1
不要笑,我学习慢了:)
谢谢s,
Hi All,
Could someone help me out with this?
items = (''a'', ''b'', ''c'', ''d'')
items + 1 = ( ''b'', ''c'', ''d'', ''a'')
items + 2 = ( ''c'', ''d'', ''a'', ''b'')
items + 3 = ( ''d'', ''a'', ''b'', ''c'')
trans = 1
list = (''a'', ''d'', ''b'', ''a'', ''d'', ''c'', ''b'')
#and items = +1, the list would be;
#list = (''b'', ''a'', ''c'', ''b'', ''a'', ''d'', ''c'') etc..
for idx in range(len(list)):
if trans == [1]:
list[idx] = [???]
print l1
Don''t laugh, I''m a slow learner : )
Thanks,
M
M. Clift< noone< at> here.com>写道:
M. Clift <noone <at> here.com> writes:
有人可以帮我解决这个问题吗?
items =('''',''b'',''c'' ,'''')
项+ 1 =(''b'',''c'','''',''a'')
Could someone help me out with this?
items = (''a'', ''b'', ''c'', ''d'')
items + 1 = ( ''b'', ''c'', ''d'', ''a'')
是否有必要(ab)使用+语法?如果没有,这样就足够了:
Is it necessary to (ab)use the + syntax? If not, will this suffice:
def rotate(seq,n):
...返回seq [n:] + seq [:n]
.... rotate(范围(10),1)
[1,2,3,4,5,6] ,7,8,9,0] rotate(范围(10),2)
def rotate(seq, n): .... return seq[n:] + seq[:n]
.... rotate(range(10), 1) [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] rotate(range(10), 2)
[2,3,4,5,6,7 ,8,9,0,1]
您也可能想要搜索谷歌群组以获取更多信息。如果我
理解你的问题,这已被多次询问,例如:
http://groups.google.com/groups?hl=en& lr =& ie = UTF-
8& safe = off& selm = 3c4e7b1a.1031701568%40news.mch.sni .de
[2, 3, 4, 5, 6, 7, 8, 9, 0, 1]
You also might want to search google groups for more information. If I
understand your question right, this has been asked a number of times, for
example:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-
8&safe=off&selm=3c4e7b1a.1031701568%40news.mch.sni .de
>
嗨史蒂文,
抱歉,因为我是初学者,我不认为我应该使用标题旋转
列表,因为那不是我想要的。
如果列表('''','d'',''b'',''a'', ''d'',''c'',''b'')旋转一次
当然给(''d'','b'',''a '等等......
我正在寻找的是,如果trans = 1,则列表将变为
(''b '','''',''c'',''b'','''','''',' 'c'')。
对于trans = 3,列表将是(''d'','c'',''a'','d'',''c '','''',''a'')
items =('''',''b'',''c'','' d'')
件+ 1 =(''b'',''c'','''',''''')
件+ 2 =(''c'',''d'','''',''b'')
items + 3 =(''d'',''a '',''b'',''c'')
trans = 1
list =(''a'' ,''',''b'','''','''','''',''b'')
我能想到的这样做的长/错方式如trans = 3所示,但是
必须是一些更简单的想法。
for idx in range(len(items)):
如果列表[idx:idx + 1] == [''a'']:
list [idx:idx + 1] = [''d'']
如果列表[idx:idx + 1] == [''b'']:
list [id x:idx + 1] = [''a'']
Hi Steven,
Sorry, as I''m a beginner I don''t think I should have used the title rotate
list, as that''s not what I want.
If the list (''a'', ''d'', ''b'', ''a'', ''d'', ''c'', ''b'') was rotated once it would
of course give(''d'', ''b'', ''a'' etc...
What I''m looking for is that say if trans = 1, then the list would become
(''b'', ''a'', ''c'', ''b'', ''a'', ''d'', ''c'') .
For trans = 3 the list would be (''d'', ''c'', ''a'', ''d'', ''c'', ''b'', ''a'')
items = (''a'', ''b'', ''c'', ''d'')
items + 1 = ( ''b'', ''c'', ''d'', ''a'')
items + 2 = ( ''c'', ''d'', ''a'', ''b'')
items + 3 = ( ''d'', ''a'', ''b'', ''c'')
trans = 1
list = (''a'', ''d'', ''b'', ''a'', ''d'', ''c'', ''b'')
I can think of the long/wrong way to do it as shown for trans = 3, but there
must be some simpler idea.
for idx in range(len(items)):
if list[idx:idx + 1] == [''a'']:
list[idx:idx + 1] = [''d'']
if list[idx:idx + 1] == [''b'']:
list[idx:idx + 1] = [''a'']
这篇关于列表轮换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!