Random shuffle of data from table

What I’m trying to do:
I am trying to get a random return from a data able but never get the same return twice.
I am using the random choice at the moment but it does return repetitive values
I tried using random shuffle but am not able to get it to work.I get an error…

TypeError: ‘NoneType’ does not support indexing at [Homeform.questionForm, line 25](javascript:void(0)) called from [Homeform.navigation, line 32](javascript:void(0)) called from [Homeform, line 44](javascript:void(0))

  my_list = list(app_tables.questions_choices.search())
    for n in range (5):
      row = random.shuffle(my_list)
      item = row['question_column']
      self.label_2.text = (item)
```

Random.shuffle does not work like that.

Random.shuffle is a function in itself. So instead do this

my_list = list(app_tables.questions_choices.search())
random.shuffle(my_list) 
    for n in range (5):
      row=my_list[n]
      item = row['question_column']
      self.label_2.text = (item)

thanks for taking alook,I appreciate it.
I have the code as below but still am getting repeat return

    random.shuffle(my_list)
    for n in range(5):
      row = my_list[n]
      item = row['question_column']
      self.label_2.text = (item)

``
am I missing something

You need to remove the brackets from this line

self.label_2.text = (item)

Make it

self.label_2.text = item

I gave that a go but still get repetition

What repetition error do you get

Can you copy the exact error that pops up when you run this code

sorry maybe I wasn’t clear
I dont get an error but the return to self.label_2 is repetitive
I only want to go through the table once and never get the same return

Oh okay I got it. This is actually happening because your loop is constantly setting the value to same label. To avoid this, you can use Repeating Panel

Or add new labels to your form in a loop

I gave it a try but , no success
I am trying to iterate through a data table list and return the individual items in a column one at a time without repeating any,to a label

Were you able to understand the docs at repeating Panel? Repeating Panel is easier to use once learned but if you are uncomfortable with it, you can use the standard loop


my_list = list(app_tables.questions_choices.search())
random.shuffle(my_list) 
for n in range (5):
      row=my_list[n]
      item = row['question_column']
      Mylabel=Label(text=item)
      self.add_component(Mylabel)

thanks I’ll keep trying
Appreciate the guidence

1 Like