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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:17:09+00:00 2026-05-23T23:17:09+00:00

I very new to programming and I have a simple problem that I just

  • 0

I very new to programming and I have a simple problem that I just do not know the syntax to. I have a regular text file that I want to substitute all of the letters for numbers. i.e. if I find an “a” or an “A”, I want to substitute the number “1”. If I find a “b” or “B” I want to substitute the number “2” ect. Can someone help me with this, I know it is most basic but I am trying to learn to program on my own and it is quite difficult. Thank-you!

  • 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-23T23:17:10+00:00Added an answer on May 23, 2026 at 11:17 pm

    This is something of an overcomplicated answer, but it has several useful Python concepts which you should at some stage learn. Here’s the simple version:

    with open(<path to file>) as f:
        for line in f:
            for char in line:
                if char.isalpha():
                    print ord(char) - ord("a") + 1
    

    The first line handles opening (and closing) the file. The second iterates over all the lines of the file. The third iterates over each character in the line. The fourth checks to see whether the character is a letter or not (what is the number of “.”, say?). The fifth does the magic: ord changes a letter into its ASCII code, which is an integer. Since the codes don’t start at one, you have to subtract the code of “a” first.


    As an exercise for later, here’s a more generic version that takes any string and yields the characters in the string one at a time. Let me know if you want me to explain it.

    >>> def transformed(it):
    ...     it = iter(it)
    ...     for char in it:
    ...             if char.isalpha():
    ...                     yield ord(char) - ord("a")
    ...
    >>> list(transformed("hello, world"))
    [7, 4, 11, 11, 14, 22, 14, 17, 11, 3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very much new to programming and have been doing fairly well so far.
I'm very new to programming and I am trying to write a program that
I am very new to C++ programming and you will see why. I want
First off I am very new to Objective C and iPhone programming. Now that
Im new to programming and I dont know very much about but I'm making
im new to iphone sdk programming, and have been stuck on this problem for
Ok so I am very new to the Android SDK, but not to programming.
I am very new to programming. I want to be able to run this
I'm currently looking at a simple programming problem that might be fun to optimize
I am very new to programming with jQuery and I am trying to retrieve

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.