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 8783787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:55:00+00:00 2026-06-13T20:55:00+00:00

i am a newbie in python and facing issue in getting this output a

  • 0

i am a newbie in python and facing issue in getting this output

 a = [('textVerify', 'AH', 'SELECT SERVICES'), ('textVerify', 'F7', 'test1>'),('audioVerify', '091;0'), ('imageVerify', 'duck.gif'),('imageVerify', 'egg.gif')]

i want to create a new list which should hold all the 0th unique element like

  audioVerify,imageVerify,textVerify

so the result expected is

 ['textVerify',(('AH', 'SELECT SERVICES'), ('F7', 'test1>'))  'audioVerify', ('091;0'),  ('imageVerify', ('duck.gif','egg.gif')]
  • 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-13T20:55:01+00:00Added an answer on June 13, 2026 at 8:55 pm

    You’d better use a defaultdict for this:

    >>> from collections import defaultdict
    >>> d = defaultdict(list)
    >>> for item in a:
    ...     d[item[0]].append(item[1:])
    ...
    >>> d
    defaultdict(<class 'list'>, {'textVerify': [('AH', 'SELECT SERVICES'), 
    ('F7', 'est1>')], 'imageVerify': [('duck.gif',), ('egg.gif',)], 
    'audioVerify': [('091;0',)]})
    

    Now you can access its elements by name/index:

    >>> d['textVerify']
    [('AH', 'SELECT SERVICES'), ('F7', 'test1>')]
    >>> d['textVerify'][0][0]
    'AH'
    

    If you need to preserve the order of the dictionary keys, you can use an OrderedDict, together with the .setdefault() method, as described by Ashwini Chaudhary:

    >>> d = OrderedDict()
    >>> for x in a:
    ...     d.setdefault(x[0],[]).append(x[1:])
    ...
    >>> d
    OrderedDict([('textVerify', [('AH', 'SELECT SERVICES'), ('F7', 'test1>')]), 
    ('audioVerify', [('091;0',)]), ('imageVerify', [('duck.gif',), ('egg.gif',)])])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python newbie getting a bit frustrated with the csv module. At this rate, it
I'm newbie in Python. I can't understand why this code does not work: reOptions
I'm newbie in Python. I have this simple code a = 0 b =
I'm a python newbie so I apologize in advance if this question has been
I'm a Python newbie. How come this doesn't work in Python 3.1? from string
I am Python newbie, so maybe don't knew if this is obvious or not.
I'm a Python newbie, so I'm sure this is easy. Here's the code in
I'm newbie in Python, but this question is not a homework (actually this code
Hi this is newbie in python, I want write a prioritized decorator which will
is this correct way of doing.i am a newbie python class main(threading.Thread): queueLock =

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.