M
M
mldwnk2021-07-27 20:50:57
Python
mldwnk, 2021-07-27 20:50:57

How to add to a variable in an array its unit along the length of the array?

I have an array where the wow variable initially takes 0.
I want to add +1 to each variable (wow) through the for loop along the length of the array (text)
But I don’t know how to do this, because if so text[0][1] then there is no point anyway :D

here is the code:

wow = 0
text = ([
  ["text1", wow],
  ["text2", wow],
  ["text3", wow],
  ["text4", wow],
  ["text5", wow],
  ["text6", wow],
  ["text7", wow],
  ["text8", wow],
  ["text9", wow],
  ["text10", wow],
])

for i in range(len(text)):
  pass

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-07-27
@mldwnk

Basically, you can make a dictionary:

wow = 0
keys = [
  ["text1", wow],
  ["text2", wow],
  ["text3", wow],
  ["text4", wow],
  ["text5", wow],
  ["text6", wow],
  ["text7", wow],
  ["text8", wow],
  ["text9", wow],
  ["text10", wow],
]
keys = [i[0] for i in keys]
text = dict((key, value) for value, key in enumerate(keys))
print(text)

If you really want a list of lists, then this is how you can:
wow = 0
keys = [
  ["text1", wow],
  ["text2", wow],
  ["text3", wow],
  ["text4", wow],
  ["text5", wow],
  ["text6", wow],
  ["text7", wow],
  ["text8", wow],
  ["text9", wow],
  ["text10", wow],
]
keys = [i[0] for i in keys]
text = [[key, value] for value, key in enumerate(keys)]
print(text)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question