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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:06:15+00:00 2026-05-28T07:06:15+00:00

I was working on a somewhat gimmick problem in regard to tuples and finally

  • 0

I was working on a somewhat gimmick problem in regard to tuples and finally solved it… but I felt that my coding is really ugly. Is there any pythonic/more simple way? Basically, the question gives you a tuple and that you need to sort tuple, remove numbers from same tuple, and then create an output like this.

OUTPUT = [this, sentence, should, now, make, sense]

At beginning, you have…

t=[(4,'make'),(1,'sentence'),(0,'this'),(3,'now'),(5,'sense'),(2,'should')] 

My solution

t=[(4,'make'),(1,'sentence'),(0,'this'),(3,'now'),(5,'sense'),(2,'should')] 

def makeList(t):
    result = ''
    t.sort()
    for x, y in t:
        result += y +', '
    result = result[:-2]    
    result = ('[' + ', '.join([result]) + ']')
    return result 

OUTPUT: [this, sentence, should, now, make, sense] 
  • 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-28T07:06:16+00:00Added an answer on May 28, 2026 at 7:06 am

    That’s easy:

    sentence = [(4,'make'),(1,'sentence'),(0,'this'),(3,'now'),(5,'sense'),(2,'should')]
    print "[%s]" % ', '.join(word for _,word in sorted(sentence))
    

    There are several things to note here:

    • A generator is used as an argument to join. The syntax is the same as for list comprehensions
    • we iterate over the sorted list of tuples and use _ to denote that we don’t need the first value of the tuple (the number), but only the second part (the word)
    • A C-style format string is used to build the final string with [] around it. We could also have used str.format here, but I think it looks cleaner this way (in this example)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inherited a somewhat messy query that I am working on refactoring to
I am somewhat new to JAVA. I've been working with it in college, but
I'm working with a Query constructor and thus am somewhat constrained in that I
I'm working on a fairly complex Android application that requires a somewhat large amount
This is a somewhat unusual problem. I'm presently working on an effort to automate
I'm working on a somewhat large project that will eventually be loaded on Azure.
I'm working on converting a rather large (but somewhat simple) app from Symfony to
I am working on a prototype for a project that is somewhat similar to
I'm working on changing over a large, somewhat poorly written (but not terribly so),
The OS I'm working on (IBM CNK, which is not Linux, but somewhat POSIX-compliant)

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.