×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    9

    Sorting Contacts

    Hey, Is there any way to sort the contacts that are grabbed with Python?

    I'm currently using:
    Code:
    db = contacts.open()
    names = []
    numbers = []
    for i in db:
      names.append(db[i].title)
      num = db[i].find('mobile_number')
      if num:
        numbers.append(num[0].value) # first mobile
      else:
        numbers.append(None)
     
    i = appuifw.selection_list(names)
    print 'Number =', numbers[i]
    To show all the contacts in the phone, but they are sorted by when they were added.

    I would like them sorted alphabetically if possible, thanks.

    Aden.

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Sorting Contacts

    Simply add a sort() instrunction to the code.

    Your code should be:
    Code:
    db = contacts.open()
    names = []
    numbers = []
    for i in db:
      names.append(db[i].title)
      num = db[i].find('mobile_number')
      if num:
        numbers.append(num[0].value) # first mobile
      else:
        numbers.append(None)
    
    names.sort()  #Sorts the list of names alphabetically
    i = appuifw.selection_list(names)
    print 'Number =', numbers[i]

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    9

    Re: Sorting Contacts

    Cheers man, Worked like a treat!

    I tried db.sort() but that obviously didn't wokr :P

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    11

    Re: Sorting Contacts

    Sadly this doesn't sort in a user friendly way.
    Code:
    item.title
    on my contacts db is "Gates Bill" rather than "Bill Gates" even if it's entered as firstname:Bill, last_name:Gates.

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Sorting Contacts

    hi peppebe
    i think the problem is not with the code. The problem is the way in which you have stored the number.
    Hope u got it.
    give a feedback.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    9

    Re: Sorting Contacts

    Problem guys!

    The sorting code
    Code:
    names.sort()
    works to sort the names alphabetically BUT.. the numbers aren't sorted with the names. So, when a name is selected from the list.. a number relating to another contact is used. Any ideas? Perhaps a array could be used??

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Sorting Contacts

    hi adenbeckitt again
    yes that is the problem actually the sorting is done on the basis of name and this code sorts only the name label of the contacts db.
    if you want to sort the number also then you have to sort the number parallely with the name.
    hope you understood what i want to tell you
    give a feedback

  8. #8
    Regular Contributor
    Join Date
    Dec 2007
    Location
    India
    Posts
    133

    Re: Sorting Contacts

    Quote Originally Posted by adenbeckitt View Post
    Problem guys!

    The sorting code
    Code:
    names.sort()
    works to sort the names alphabetically BUT.. the numbers aren't sorted with the names. So, when a name is selected from the list.. a number relating to another contact is used. Any ideas? Perhaps a array could be used??
    That will be an issue when you only sort the names and not the numbers,
    I would suggest to sorting the numbers simultaneously as the respective names are sorted out. This will solve the problem I guess, do a little work around with it.
    Kandyfloss

    V 7.0642.0
    18-10-06
    RH-51
    Nokia 7610

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    9

    Re: Sorting Contacts

    I was thinking of just doing a numbers.sort() thing but that wouldn't work because it would sort the numbers alphabetically and not to the corresponding name... Any ideas? I'm pretty new to Python.

  10. #10
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Sorting Contacts

    hi adenbeckitt
    the problem is with the logic try to make a new logic to sort out a number with name label.
    best regards

Similar Threads

  1. About Encryption of Contacts in PhoneBook
    By jennie in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2007-10-12, 07:45
  2. Replies: 6
    Last Post: 2007-04-24, 21:36
  3. PIM API adding new contacts problem
    By hoppelmoppel in forum Mobile Java General
    Replies: 3
    Last Post: 2007-04-22, 17:12
  4. Nokia 6600 Sorting Contacts
    By agoujet in forum General Development Questions
    Replies: 0
    Last Post: 2003-11-30, 14:47
  5. Replies: 0
    Last Post: 2003-09-02, 16:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •