Thread: Sort a list!

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    21
    Rep Power
    0

    Sort a list!


    Hey guys,

    I have a list and I wanna sort it alphabeticly.

    Can someone help me?

    I have this List for example:

    {'Tel': '01634498766', 'Addresse': 'Berlinerallee 19', 'User': 'Max', 'ID': '111'}


    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    19
    This is a dictionary. Do you want to sort it according to the keys? If so, try this:

    Code:
    D = {'Tel': '01634498766', 'Addresse': 'Berlinerallee 19', 'User': 'Max', 'ID': '111'}
    for k in sorted(list(D.keys())):
    	print (k, D[k])
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    21
    Rep Power
    0
    I want to sort my xml attributes, because it output me two different dict if I change one Attribute.


    I tried this code, but it doesn't work.
    This code shoud traverse and compare my two xml attributes and the values.

    code Code:
    for element1, element2 in zip(tree1.iter(), tree2.iter()):
    	if element1.tag == element2.tag:
    		if element1.attrib and element2.attrib:
    			for k in sorted(list(element1.keys())):
    				print (k, element1[k])]

IMN logo majestic logo threadwatch logo seochat tools logo