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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:37:51+00:00 2026-06-06T02:37:51+00:00

I am currently trying to implement Conway’s Game of Life in a Code, and

  • 0

I am currently trying to implement Conway’s Game of Life in a Code, and therefore built a function which generates the coordinates depending of the size of the window.

def coords_maker(num_x, num_y):

    num_x += 1  
    num_y += 1  
    coords = []
    for i in range (0,num_y, 1):    
        for n in range (0,num_x,1):
            coords.append ('x'+str(n)+'y'+str(i))   
    return coords

Yet, I would like to randomly assign values to the resulting strings, to mark them either as alive (1) or dead (0). However they only way to convert a string to a variable name known to me is via a dict and var(), but however, it is essential for the further code that the coordinates stay sorted, as I want to be able to iterate over the ordered items and put the cursor accordingly to the coordinates name. Something like:

print ('\033['+X_COORD+';'+Y_COORD+'f'+ x1y5) 

if e.g. x1y5 is the corresponding value (0 or 1) of the variable

Is there a convenient method how to either do this via a dict or how to convert the name of the strings to variable names?
Or probably. If I keep one dict and one list and store the coordinate names in the list and the values in the dict?

Thank you in advance!
kyril

  • 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-06T02:37:53+00:00Added an answer on June 6, 2026 at 2:37 am

    You use a dictionary:

    def coords_maker(num_x, num_y):
    
        num_x += 1  
        num_y += 1  
        coords = {}
        for i in range (0,num_y, 1):    
            for n in range (0,num_x,1):
                coords['x'+str(n)+'y'+str(i)] = 0
        return coords
    

    You then access the value with

     coords[x][y]
    

    And change it like so:

     coords[x][y] = 1
    

    Now, of course this converting of coordinates to strings is completely pointless. Simply use a list of lists:

    def coords_maker(num_x, num_y):
    
        num_x += 1  
        num_y += 1  
        coords = [[0]*num_x for x in range(num_y)]
        return coords
    

    And I don’t know why you add 1 to the coordinates either:

    def coords_maker(num_x, num_y):
        return [[0]*num_x for x in range(num_y)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement Conway's Game of Life on an embedded device. I've only
I'm currently trying to implement a simple Add-In for InfoPath 2010 Filler/Editor mode, which
I'm currently trying to implement something that combines reverse engineering and graph theory. Therefore
Hey guys, I'm currently trying to implement a function using C that takes in
I'm currently trying to implement a fully autonomous Pac-Man game, where you just watch.
I am currently trying to implement some code using Android to detect when a
I'm currently trying to implement some reporting functionality which requires me to transform some
I am currently trying to implement a Swing component, inheriting from JLabel which should
I am currently trying to implement the built-in Silverlight 3 validation against objects that
I am currently trying to implement this into my current code: http://cubiq.org/iscroll I have

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.