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

  • Home
  • SEARCH
  • 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 9019001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:40:18+00:00 2026-06-16T04:40:18+00:00

I have a python program which prints out some lists which are created by

  • 0

I have a python program which prints out some lists which are created by other python programs in the format of:
[0, [], 0, 1, [], 1]

And I would like to change the 0’s and 1’s to letters, i.e. in the above input, I want to have
[x, [], x, y, [], y] as output

So far my code to do this looks like:

for x in search.Search(s, s.run()):
    if x == 0:
        return x
    elif x == 1
        return y

I know I’m missing something but I’m not too sure what 🙁

  • 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-06-16T04:40:19+00:00Added an answer on June 16, 2026 at 4:40 am

    Use a list comprehension:

    subst = {0: 'x', 1: 'y'}
    return [subst.get(v, v) if v else v for v in search.Search(s, s.run()]
    

    By using return you exit the loop early.

    The if v else v helps avoid attempting to use the empty lists as keys (which would raise a TypeError; lists are not hashable and thus not allowed as keys). The alternative strategy would be:

    from collections import Hashable
    
    subst = {0: 'x', 1: 'y'}
    hashable = lambda v: isinstance(v, Hashable)
    return [subst.get(v, v) if hashable(v) else v for v in search.Search(s, s.run()]
    

    The subst map is a little easier to extend; but using a function to map the value (as used in Jacob’s answer) could be more readable to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python program which calls a C function. I send some structures
I have a Python CGI program which prints datetime values. The timestamps are all
I have a save function within my Python program which looks like this: def
I have a source of python program which doesn't have any documentation or comments.
I have a small Python OOP program in which 2 class, Flan and Outil
I have a python program that I am currently working on which is working
I have a small Python program, which uses a Google Maps API secret key.
I have this program in Python which should save text files to a folder
I have a python script that runs a program, which generates few .exe files
I have been trying to create a simple program with Python which uses OpenCV

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.