Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8824019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:30:12+00:00 2026-06-14T06:30:12+00:00

List duplicate data concatenation in python This is in continuation of list issue but

  • 0

List duplicate data concatenation in python

This is in continuation of list issue but here I want to preserve the order of the dict

listData=[('audioVerify', '091;0'), ('imageVerify', 'icon091.gif'), ('bufferVerify', '\x01?')]
    methodList = {}
for item in listData:
    methodList.setdefault(item[0],[]).append(item[1:])
for method in methodList:
    arguments = methodList[method]
    s = [method,arguments]
    print s

when I iterate the list it gives the following

  ['audioVerify', [('091;0',)]]
  ['bufferVerify', [('\x01?',)]]
  ['imageVerify', [('icon091.gif',)]]

but what are the possibilities where I can preserve the order as below:

  ['audioVerify', [('091;0',)]]
  ['imageVerify', [('icon091.gif',)]]
  ['bufferVerify', [('\x01?',)]]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:30:13+00:00Added an answer on June 14, 2026 at 6:30 am

    I have just what the doctor ordered: OrderedDict

    From the examples:

    >>> from collections import OrderedDict
    >>> # regular unsorted dictionary
    >>> d = {'banana': 3, 'apple':4, 'pear': 1, 'orange': 2}
    
    >>> # dictionary sorted by key
    >>> OrderedDict(sorted(d.items(), key=lambda t: t[0]))
    OrderedDict([('apple', 4), ('banana', 3), ('orange', 2), ('pear', 1)])
    
    >>> # dictionary sorted by value
    >>> OrderedDict(sorted(d.items(), key=lambda t: t[1]))
    OrderedDict([('pear', 1), ('orange', 2), ('banana', 3), ('apple', 4)])
    
    >>> # dictionary sorted by length of the key string
    >>> OrderedDict(sorted(d.items(), key=lambda t: len(t[0])))
    OrderedDict([('pear', 1), ('apple', 4), ('orange', 2), ('banana', 3)])
    

    If you have an older versions of python, consult this other SO question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: IList<T> to IQueryable<T> I have a List data, but I want a
Possible Duplicate: Python list append behavior Why does this code: x = [[]]*3 x[0].append('a')
Possible Duplicate: Python: How to find list intersection? I have two lists of data
Possible Duplicate: Get a list of dates between two dates This is my sql:
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
I am trying to list all the duplicate records in a table. This table
Possible Duplicate: Java add all table data into list +--------+-------+-----+ | Name |number |qty
Possible Duplicate: How can I turn a list into an array in python? How
Possible Duplicate: How to put a List in intent I want to pass a
Possible Duplicate: How many data a list can hold at the maximum What is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.