【问题标题】:Flutter : How creat new list with changed index from exist list?Flutter:如何从现有列表中创建具有更改索引的新列表?
【发布时间】:2021-09-19 07:34:41
【问题描述】:

如果我在 Flutter 中有这个列表:

var myList = ["a","b" , "c" , "d"];

如何通过随机索引为每个值从 myList 创建新列表,例如:

   ["b","c" , "a" , "d"];

或:

   ["a","c" , "d" , "b"];

或任何其他随机列表

【问题讨论】:

    标签: list flutter dart random


    【解决方案1】:
    var newList = [...myList];
    newList.shuffle();
    

    【讨论】:

      【解决方案2】:
      import random
      
      myList = ["a","b" , "c" , "d"];
      random.shuffle(myList)
      
      print(mylist)
      

      你关注这个 https://www.w3schools.com/python/ref_random_shuffle.asp

      【讨论】:

      • 这是给 python 的,我需要在 dart 中
      【解决方案3】:

      试试这个:

      var myList = ["a", "b", "c", "d"];
      myList.shuffle();
      

      【讨论】:

        猜你喜欢
        • 2019-12-27
        • 2018-09-24
        • 2021-07-04
        • 2020-03-08
        • 1970-01-01
        • 2020-05-23
        • 1970-01-01
        • 2021-03-02
        • 2015-04-19
        相关资源
        最近更新 更多