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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:04:28+00:00 2026-05-31T13:04:28+00:00

All right, I’m a novice at python, and here’s the snippet of code in

  • 0

All right, I’m a novice at python, and here’s the snippet of code in question:

<!-- language: lang-py -->

List = [["W","w"],["A","A"],["a","a"]]

def ascii():
    x = 0
    y = 0
    aValues = [[],[],[]]
    for item in List:
        for item in List[x]:
            c = "0" 
            c = ord(List[x[y]])
            y = y + 1
            aValues[x].append(c)
        x = x + 1

    return aValues
aValues = ascii()
print (aValues)

And, when I try to execute this, I get this error message:

>>> 
Traceback (most recent call last):
  File "/Users/Hersh/Desktop/Python/ascii_conversion.py", line 16, in <module>
    aValues = ascii()
  File "/Users/Hersh/Desktop/Python/ascii_conversion.py", line 10, in ascii
    c = ord(List[x[y]])
TypeError: 'int' object is not subscriptable
>>> 

What exactly is the problem, and how can I fix 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-31T13:04:29+00:00Added an answer on May 31, 2026 at 1:04 pm

    I’m not sure of what exactly you intend to do with the function, it has several errors. Try this and tell me if this is what you wanted:

    List = [["W", "w"], ["A", "A"], ["a", "a"]]
    aValues = [[ord(e1), ord(e2)] for e1, e2 in List]
    print(aValues)
    

    EDIT 1 :

    Alternatively, if each sublist contains more than two elements, this version is better and will work for the general case:

    aValues = [map(ord, pair) for pair in List]
    

    EDIT 2 :

    According to the comments, you need to use a function. All right, then let’s implement the solution as a function – first thing, the input for the function should be received as a parameter, not as a global variable (List) as you have currently in your code. Then, the result will be returned, and I’ll take the opportunity to show yet another way to solve the problem at hand:

    def ascii(lst):
        return [[ord(element) for element in pair] for pair in lst]
    

    Use it like this:

    List = [["W", "w"], ["A", "A"], ["a", "a"]]
    ascii(List)
    > [[87, 119], [65, 65], [97, 97]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

right now i am simply ftping everything (all of my source code included) but
All right, you guys were very helpful with my last question, so I'll try
I use AutoBean to code/decode data to JSON and that was all right in
All right. The problem here is pretty abstract. Bear with me. I have a
All right real quick question guys. I know that C# Forms have the OnPaint()
All right, so here's a challenge for all you SQL pros: I have a
All right guys and gals it's time for the age old question, how do
All right, this must be an absolutely easy question, and I apologize for that.
All right, so previously I asked... SOAP Prototype AJAX SOAPAction Header Question (can't hyperlink
All right all, So I've got a UITableView that is inited in applicationDidFinishLaunching like

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.