2017-08-01 14 views
0

私はプログラミングに慣れていないので、私はpythonに関するコースから始めます。誰かが私に私は文字列から最初の文字を取得し、それを他の文字列のインデックスにする必要があります。

例えば
>def cipher(map_from, map_to, code): 
    """ map_from, map_to: strings where each contain 
          N unique lowercase letters. 
     code: string (assume it only contains letters also in map_from) 
     Returns a tuple of (key_code, decoded). 
     key_code is a dictionary with N keys mapping str to str where 
     each key is a letter in map_from at index i and the corresponding 
     value is the letter in map_to at index i. 
     decoded is a string that contains the decoded version 
     of code using the key_code mapping. """ 

を助けることができるので、もし私が、やる方法がわからないこの演習、

cipher("abcd", "dcba", "dab")リターン(辞書内のエントリの順序と同じではないかもしれない)({'a':'d', 'b': 'c', 'd': 'a', 'c': 'b'}, 'adc')

答えて

0

文字のインデックスは0から始まります。ヒントを提供する必要があります。

>>> 'abcdefgh'.find('e') 
4 
>>> 'abcdefgh'[4] 
'e' 
関連する問題