Итак, у меня есть этот сценарий.
lista = [0,0,0,0,0,0,0,'X',0,0]
jump = 5
lista2 = list()
for i in range(10):
lista2.append(0)
for lettera in lista:
# check if list[i] + jump is more then list len, if FALSE put that 'X' in place,
# if TRUE go throught list and go back to lista[0] and put that 'X' in rightplace.
# example: len_list = 10 | start_position = list[7] | jump = 5 | final_position = list[2]
# rember that count start on list[0]
control = lista.index(lettera) + jump
if control < len(lista):
lista2[lista.index(lettera)] = lettera
else:
differenza = control - len(lista)
lista2[differenza] = lettera
print(lista2)
, вот и все. Все работает правильно? Теперь попробуйте следующее:
msg = 'GAr cnff78eq vfGr8L4qetPEsslog32gdsoRK8XSP6x2RHh'
msgSplit = []
msgShuffle = list() #where the final product goes
for i in range(len(msg)): #start with a the same numbers of element(msg)
msgShuffle.append('*')
def split_msg(msg):
#split msg letter into list
for i in msg:
msgSplit.append(i)
return msgSplit
def shuffle_msg(lista,lista2):
for i in lista:
control = lista.index(i) + 13 #13 here is the 'jump'
if control < len(lista):
lista2[lista.index(i)] = i
else:
differenza = control - len(lista)
lista2[differenza] = i
################# T E S T #################
split_msg(msg)
print(msgSplit)
print('----------------')
shuffle_msg(msgSplit, msgShuffle)
print(msgShuffle)
если вы запускаете эту программу, это вывод:
['G', 'u', 'r', ' ', 'c', 'n', 'f', 'f', 'j', 'b', 'e', 'q', ' ', 'v', 'f', ' ', '5', 'G', 'r', '8', 'L', '4', 'q', 'e', 't', 'P', 'E', 's', 'P', 'k', '8', 'h', 't', 'q', 'j', 'h', 'R', 'K', '8', 'X', 'S', 'P', '6', 'x', '2', 'R', 'H', 'h']
----------------
['G', 'R', 'K', ' ', 'X', 'S', 'f', '6', 'x', '2', 'e', 'H', '', 'v', '', '', '5', '', '', '8', 'L', '4', '', '', 't', 'P', 'E', 's', '', 'k', '', 'h', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
первая строка разбита на список (msgSplit), вторая - msgSplit после я передал его в функцию (shuffle_msg), которую вы можете увидеть в скрипте.
80% элемента теперь ''. так в чем проблема??? функция просто должна переместить элемент в списке.
спасибо!
это идея:
@ = list[4]
so now we want to move @ forward for 3 position:
[o,o,o,o,@,o] start @=list[4]
[o,o,o,o,o,@] +1 @=list[5]
[@,o,o,o,o,o] +2 the list is finish so we continue from @=list[0]
[o,@,o,o,o,o] +3 finish on @=list[1]