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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:00:19+00:00 2026-05-31T20:00:19+00:00

I really have no idea how to go about this. So far all I

  • 0

I really have no idea how to go about this. So far all I have is this:

alphabet = 'abcdefghijklmnopqrstuvwxyz'

I am supposed to go through a text file and count the number of words in alphabetical order.
I can’t do

if word in alphabet:

because that requires the word to actually have all of those letters in order.

To clarify: ‘blow’ would pass the test and ‘suck’ would not.
I have a list of thousands of words, I need to go through the entire list and count the numbers of words that are in alphabetical order. Sorry for any prior confusion.

  • 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-31T20:00:20+00:00Added an answer on May 31, 2026 at 8:00 pm

    Very simple:

    >>> alphabet = 'abcdefghijklmnopqrstuvwxyz'
    >>> list(alphabet) == sorted(alphabet)
    True
    >>> list('blow') == sorted('blow')
    True
    >>> list('suck') == sorted('suck')
    False
    

    So know we can define the predicate we need:

    >>> alphabetical = lambda w: list(w.lower()) == sorted(w.lower())
    

    And apply it to a list:

    >>> lst = ['blow', 'suck', 'abc']
    >>> filter(alphabetical, lst)
    ['blow', 'abc']
    

    From there it’s not a large step to counting the results 🙂 There’s some other things to consider:

    • The sorting is O(n*log n), although this problem could easily be solved in O(n). This is probably okay because words usually have a bounded number of characters and sorted is implemented in C and thus very fast
    • If you really need efficiency, you can even use the sum(1 for w in w if ...) trick, which uses a generator expression instead of building a list.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really have no idea why I'm struggling with this so much. I'm scraping
I have really no idea why I'm asking this as this a really completely
This probably sounds really stupid but I have noo idea how to implement jquery's
I have a problem and I really have no idea how to fix it.
It doesn't really have to add newlines, just something readable. Anything better than this?
This is what I have so far, but it doesn't seem to match http://zorc.breitbandkatze.de/crc.html
I really have big problems with importing an extern C-Library to my existing C++-Project.
I really have a problem, I have a VS 2010 solution and it suddenly
Do I really have to learn Objective-C to develop solid Mac Apps? As Mac
Since batch doesn't really have ints, I have to work around it with set

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.