Need to reorder list and make a sentence in python
Question: I need help rearranging this 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" by indexing into the array. How exactly do I do that? I'm a
beginner and I'm doing this in python 2.7.


Answer: As has been mentioned, your list can be sorted alphabetically by using the
sort() function as 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 your 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 you go on to say 'index into' for 'hello world'. If you mean you want to
create a simple cypher then this could be easily be achieved as follows:

    
    
    import string
    
    s_from = 'abcdefghijklmnopqrstuvwxyz '
    s_to = 'zabycxdwevfguhijtklsmnropq '
    cypher_table = string.maketrans(s_from, s_to)
    print "hello world".translate(cypher_table)
    

This would convert your text as follows:

    
    
    wcggi rikgy
    

Please could you edit your question to give an example of what you are trying
to achieve.

