+ 1

i want to make a code that split a word to letters and then plus the number of positon of each letter together and then etc

s=0 word=input("Enter A Word:") lenght=len(word) letterlist=list(word) letterlist=[ch for ch in word] print(letterlist) chars=['a''b''c''d''e''f''g''h''i''j''k''l''m''n''o''p''q''r''s''t''u''v''w''x''y''z'] nums=['1''2''3''4''5''6''7''8''9''10''11''12''13''14''15''16''17''18''19''20''21''22''23''24''25''26']

28th Jan 2019, 9:38 AM
Mohammad Javad Bidari
Mohammad Javad Bidari - avatar
5 Answers
+ 4
One way: x=input() print(*(''.join((b, str(a))) for (a, b) in enumerate(x, 1)))
28th Jan 2019, 10:11 AM
HonFu
HonFu - avatar
+ 2
HonFu Can you explain your code, please? I'm not great at Python and I'm not sure the asker is either.
28th Jan 2019, 11:06 AM
James
James - avatar
+ 2
enumerate takes an iterable and puts a number to each element, like 'a' becomes (0, 'a'). If we add a second argument, we can specify where the counting starts. For every element of that, we now turn the number into a string, then connect the two strings using the join method. After that we get a succession like 'a1', 'b2' and so on, which we unpack using the *, and print.
28th Jan 2019, 11:21 AM
HonFu
HonFu - avatar
+ 2
HonFu thankU your answer will help me too much
30th Jan 2019, 8:40 AM
Mohammad Javad Bidari
Mohammad Javad Bidari - avatar
0
If you want this to be some kind of secret cipher, you should change the single digit numbers into two digit numbers: 1, 2, 3 into 01, 02, 03. Otherwise, you won't be able to decipher it.
28th Jan 2019, 11:05 AM
James
James - avatar