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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:58:02+00:00 2026-05-27T02:58:02+00:00

Working my way through Learn Python the Hard Way ex.25, and I just can’t

  • 0

Working my way through Learn Python the Hard Way ex.25, and I just can’t wrap my head around something. Here’s the script:

def break_words(stuff):
    """this function will break waords up for us."""
    words = stuff.split(' ')
    return words

def sort_words(words):
    """Sorts the words."""
    return sorted(words)

def print_first_word(words):
    """Prints the first word after popping it off."""
    word = words.pop(0)
    print word

def print_last_word(words):
    """Prints the last word after popping it off."""
    word = words.pop(-1)
    print word

def sort_sentence(sentence):
    """Takes in a full sentence and returns the sorted words."""
    words = break_words(sentence)
    return sort_words(words)

def print_first_and_last(sentence):
    """Prints the first and last words of the sentence."""
    words = break_words(sentence)
    print_first_word(words)
    print_last_word(words)

def print_first_and_last_sorted(sentence):
    """Sorts the words, then prints the first and last ones."""
    words = sort_sentence(sentence)
    print_first_word(words)
    print_last_word(words)

When running the script, break_words will use any argument I create if I use the command break_words(**). So I can type

sentence = "My balogna has a first name, it's O-S-C-A-R"

and then run break_words(sentence) and end up with a parsed “‘My’ ‘balogna’ ‘has’ (…).

But other functions (like sort_words) will only accept a function with the name “words.” I must type
words = break_words(sentence)

or something for sort_words to work.

Why can I pass any argument in the parentheses for break_words, but only arguments that are actually attributed to “sentence” and “words” specifically for sort_words, print_first_and_last, etc.? I feel like this is something fundamental that I should understand before I move on in the book, and I just can’t get my head around it.

  • 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-27T02:58:02+00:00Added an answer on May 27, 2026 at 2:58 am

    It’s about the type of value that each function accepts as its parameter.

    break_words returns a list. sort_words uses the built-in function sorted(), which expects to be passed a list. This means that the parameter you pass to sort_words should be a list.

    Maybe the following example illustrates this:

    >>> sort_words(break_words(sentence))
    ['My', 'O-S-C-A-R', 'a', 'balogna', 'first', 'has', "it's", 'name,']
    

    Note that python defaults to being helpful even though this can at times be confusing. So if you pass a string to sorted(), it will treat it as a list of characters.

    >>> sorted("foo bar wibble")
    [' ', ' ', 'a', 'b', 'b', 'b', 'e', 'f', 'i', 'l', 'o', 'o', 'r', 'w']
    >>> sorted(["foo", "bar", "wibble"])
    ['bar', 'foo', 'wibble']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working through learn python the hard way , and in exercise 33 extra
While working my way through the Android tutorials, I came across something I don't
I'm currently working my way through Accelerated C++ and just came across this in
I am working my way through Learn Cocoa on the Mac which was written
I've been recently working my way through Programming Language Pragmatics 3rd ed to learn
I have been working my way through Scott Guthrie's excellent post on ASP.NET MVC
I'm working my way through some ASP.NET MVC reading and I have a web
I'm working my way through Agile Web Development with Rails and am running into
I'm still working my way through some pretty basic Actionscript programming (in Flex), and
I've been working my way through Tim Heuer's Silverlight tuturial , in which you

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.