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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:31:23+00:00 2026-05-29T16:31:23+00:00

I have a list in python. This list has sublist in it. for example:

  • 0

I have a list in python. This list has sublist in it.
for example:

 [['85.', 'Document', 'will', 'discuss', 'allegations,', 'or', 'measures', 'being', 'taken', 'against,', 'corrupt', 'public', 'officials', 'of', 'any', 'governmental', 'jurisdiction', 'worldwide.'], ['56.', 'Document', 'will', 'include', 'a', 'prediction', 'about', 'the', 'prime', 'lending', 'rate,', 'or', 'will', 'report', 'an', 'actual', 'prime', 'rate', 'move.'], and so on]

when i print mylist[0], i get the following:

['85.', 'Document', 'will', 'discuss', 'allegations,', 'or', 'measures', 'being', 'taken', 'against,', 'corrupt', 'public', 'officials', 'of', 'any', 'governmental', 'jurisdiction', 'worldwide.']

when i print mylist[0][0] i get 85.

I am new to python and i dont understand how to access these values(85, 56, and so on) inside a for loop, so that i can delete all the numbers. i.e 85, 56, and so on.

  1. Also I have a similar list [[1, 23], [2, 34], [3, 45], [1, 45], [2, 44]]
    and i want to add all the second elements where the 1st element is the same. i.e i want to add 23 + 45 (because both have 1 as their 1st element). I understand i need a for loop, but i am new to python, and i am not able to understand the loops.
  • 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-05-29T16:31:23+00:00Added an answer on May 29, 2026 at 4:31 pm

    To get all the first elements:

    zip(*your_list)[0]
    

    zip(*some_iterable) does some kind of matrix inversion – you should play a bit with it to get an idea.

    To remove all the first values from a set of iterables you may choose a few ways. E.g.:

    [item[1:] for item in your_list]  # probably the best
    zip(*zip(*your_list)[1:])  # tricky and probably slow one
    

    To sum your values you’d need a dictionary:

    >>> from collections import defaultdict
    >>> l = [[1, 23], [2, 34], [3, 45], [1, 45], [2, 44]]
    >>> d = defaultdict(int)
    >>> for item in l:
        d[item[0]] += item[1]
    
    >>> d.items()
    [(1, 68), (2, 78), (3, 45)]
    

    We use defaultdict here to be able to perform this d[item[0]] += item[1] assigment. With simple dict we’d get a KeyError, since our d is empty. But defaultdict in this case just returns default value – int(), which is 0.

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

Sidebar

Related Questions

I have list in python which has following entries name-1 name-2 name-3 name-4 name-1
I have a Python list called results. Each result in the results list has
I'm new to python programming. I have this problem: I have a list of
I'm running into trouble with some Python stuff. I have a list that has
I have a list of Python objects that I want to sort by a
I have a list in Python, and I want to check if any elements
If you have a list in python, and you want the elements from 2
If you have a list in python, and want to extract elements at indices
If I have a list in python such as: stuff = [1, 2, 3,
i have an issue i could use some help with, i have python list

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.