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 8494579

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:20:20+00:00 2026-06-10T23:20:20+00:00

I have generated a long list of tuples (format below). Each tuple in the

  • 0

I have generated a long list of tuples (format below). Each tuple in the list has time as the first element and an event as the third member. The second member is always the same and identify the list from other similar lists that I will have to deal with. The tuples have many different third element and each have multiple entries at different values of time which is the first element.

I am trying to filter the list to delete all but the min and max value of time (first item in tuple) for each event (third member of tuple). I tried using list comprehension but quickly got confused.

('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3567', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3600', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', 'HORIZ_G .575')
('1.3800', 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
('1.3800', 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
'1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')

Result after filter is

('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3600', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', 'HORIZ_G .575')
('1.3800', 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
('1.3800', 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS  34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS  34.5')
'1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')`

I am trying the code below but I am getting an error. I am fairly new to this so please tell me if I am doing something incorrect. m1 in the code is my list of tuples generated from the findall. I have imported ast at the top of my code.

       m1 = re.findall(pattern1,wholefile)
       m1=[ast.literal_eval(t) for t in m1] 
       m1=[(float(a),b,c) for a,b,c in m1] 
       keys=sorted({t[2] for t in m1}) 
       for key in keys: 
           group=filter(lambda t: t[2]==key,m1)
           print '{}:\n\tmax: {}\n\tmin: {}'.format(key,max(group),min(group))
  • 0 0 Answers
  • 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-10T23:20:22+00:00Added an answer on June 10, 2026 at 11:20 pm

    This works (as long as you really have a list of tuples with the first value a float):

    keys=sorted({t[2] for t in tups})
    for key in keys:
        group=filter(lambda t: t[2]==key,tups)
        print '{}:\n\tmax: {}\n\tmin: {}'.format(key,max(group),min(group))
    

    Prints:

    MIHL G1.575:
        max: (1.38, 'VOLTAGE DEVIATION', '7MIHL G1.575')
        min: (1.36, 'VOLTAGE DEVIATION', '7MIHL G1.575')
    DIFICULT 230:
        max: (1.36, 'VOLTAGE DEVIATION', 'DIFICULT 230')
        min: (1.3533, 'VOLTAGE DEVIATION', 'DIFICULT 230')
    DNLP1_G1.575:
        max: (1.3467, 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
        min: (1.3467, 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
    DNLP2G23.575:
        max: (1.3467, 'VOLTAGE DEVIATION', 'DNLP2G23.575')
        min: (1.3433, 'VOLTAGE DEVIATION', 'DNLP2G23.575')
    FT CRK2 34.5:
        max: (1.4267, 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
        min: (1.4233, 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
    HIPLN_G .575:
        max: (1.4833, 'VOLTAGE DEVIATION', 'HIPLN_G .575')
        min: (1.48, 'VOLTAGE DEVIATION', 'HIPLN_G .575')
    HORIZ_G .575:
        max: (1.38, 'VOLTAGE DEVIATION', 'HORIZ_G .575')
        min: (1.38, 'VOLTAGE DEVIATION', 'HORIZ_G .575')
    MEDBOWCO 115:
        max: (1.38, 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
        min: (1.38, 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
    MINERS  34.5:
        max: (1.39, 'VOLTAGE DEVIATION', 'MINERS  34.5')
        min: (1.3867, 'VOLTAGE DEVIATION', 'MINERS  34.5')
    STNDPSVC 230:
        max: (1.38, 'VOLTAGE DEVIATION', 'STNDPSVC 230')
        min: (1.38, 'VOLTAGE DEVIATION', 'STNDPSVC 230')
    

    Based on your comment, sounds you do have text that LOOKS like tuples. Therefore, to convert that to actual tuples:

    import ast
    
    tups=[ast.literal_eval(t) for t in tups]
    tups=[(float(a),b,c) for a,b,c in tups]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long list generated from a simple mysql select query. Currently (shown
I have a long list of file names in a txt file, which I
After developing in PHP for a long time I have decided to step into
I have a List of HashMap 's which has key of type Integer and
I have a table in my application (generated dynamically) that has 3 columns. The
I have long tables generated by datagrid control that go beyond the page width.
First, appologies for the long post, I have tried to cut it down as
I have a long list of languages and their respective codes ( http://pastebin.com/rn4JbTtP ),
I have a long list of article titles stored in a text file, and
I currently have a generic list that is generated by ActiveScaffold. At the end

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.