0

I have a Micropython program and i have a question about one piece of code. This code is no different from regular Python, it doesn't need specific micropython libraries.

Question itself:

Funсtion 'oled.text' takes three parameters. One is string and two other are coordinates(int). How do I transfer values from list so they become parameters? Should i create 'for' cycle inside the function? If the answer is yes, how should i do it?

Sorry for my English, it not my native language

x = 6
list = {
    ('bad', 0, 0),
    ('good', 10, 10),
    ('ugly', 20, 20),
    ('bullets:', 5, 30),
    (str(x), 70, 30)
    }
for i in list:
    oled.text(i[0], i[1], i[2])
Dmitrii_Argon
  • 33
  • 1
  • 9
  • Does this answer your question? [How to extract parameters from a list and pass them to a function call](https://stackoverflow.com/questions/7527849/how-to-extract-parameters-from-a-list-and-pass-them-to-a-function-call) – mkrieger1 May 05 '20 at 10:21
  • you want to pass all list to your function? – soheshdoshi May 05 '20 at 10:28

1 Answers1

2

A list should be created using squared bracket [] instead of curly bracket {} used by set and dictionary.

For your question you should be able to achieve it using the code snippet as follow

for i in list:
    function(*i)

The * operator unpacks the tuple in the list and provides it as parameter for the function

XQ_CHIA
  • 158
  • 2
  • 7