Need to reorder list and make a sentence in python -
i need rearranging list alphabetically
list= ['z', 'a', 'b', 'y', 'c', 'x', 'd', 'w', 'e', 'v', 'f', 'g', 'u', 'h', 'i', 'j', 't' ,'k', 'l', 's', 'm', 'n', 'r', 'o', 'p', 'q', ' ']
into "hello world" indexing array. how do that? i'm beginner , i'm doing in python 2.7.
as has been mentioned, list can sorted alphabetically using sort() function follows:
mylist = ['z', 'a', 'b', 'y', 'c', 'x', 'd', 'w', 'e', 'v', 'f', 'g', 'u', 'h', 'i', 'j', 't' ,'k', 'l', 's', 'm', 'n', 'r', 'o', 'p', 'q', ' '] mylist.sort() print mylist
which results in list looking like:
[' ', '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']
but go on 'index into' 'hello world'. if mean want create simple cypher achieved follows:
import string s_from = 'abcdefghijklmnopqrstuvwxyz ' s_to = 'zabycxdwevfguhijtklsmnropq ' cypher_table = string.maketrans(s_from, s_to) print "hello world".translate(cypher_table)
this convert text follows:
wcggi rikgy
please edit question give example of trying achieve.
Comments
Post a Comment