Python Forum
Make one thing act like another
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make one thing act like another
#1
I have a long list of 750 single digit numbers.

WorldList = [0,0,3,7,3,2...]
I use the variable valIndex plus a number to call certain points in the list.

WorldList[valIndex + 30] = 0
I know that I could use an if statement every time I call a point, but could I make something at the top of my code that says "anywhere in the code where valIndex is a multiple of 30, set WorldList[valIndex+30] to 0"

so if I set valIndex to 60, then WorldList at 90 acts like 0. But as soon as valIndex changes, WorldList[90] goes back to what it was originally.

I know this is confusing and probably doesn't make sense.
Reply
#2
I would use a class with properties. Properties are attributes that allow you to set up code that is triggered when the attribute changes. So whenever valIndex changes, you could have code that automatically changes WordList as well, assuming they were both attributes of the class.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Do I understand correctly that you want:

- bind val_index name to value (object)
- calculate list index (val_index + 30) and change corresponding value in list to 0. Or do you need change all values to 0 where indices are i % 30 == 0
- do some magic
- change value in list back to original value

Question:

- can you use throwaway lists? Every time you just create new list, use it and discard? This way original list remains same
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I am confused with the key and value thing james1019 3 911 Feb-22-2023, 10:43 PM
Last Post: deanhystad
  Need help i just started the whole thing gabriel789 16 3,088 Sep-12-2022, 08:04 PM
Last Post: snippsat
  i making a terminal sign up website thing Kenrichppython 1 1,658 Nov-04-2021, 03:57 AM
Last Post: bowlofred
  use thing before self sylvanas 3 2,304 Jul-21-2021, 04:54 PM
Last Post: sylvanas
  Not able to make a specific thing pause in pygame cooImanreebro 4 3,141 Dec-13-2020, 10:34 PM
Last Post: cooImanreebro
  Help with list thing please Yeyzon 1 2,018 Apr-19-2019, 07:51 AM
Last Post: snippsat
  Printing one thing from a list bidoofis 1 2,308 Feb-05-2019, 09:02 PM
Last Post: ichabod801
  I found weird thing. catastrophe_K 1 2,061 Sep-29-2018, 09:59 AM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020