In Python How can I declare a Dynamic Array

后端 未结 3 1662
情话喂你
情话喂你 2020-12-13 01:07

I want to declare an Array and all items present in the ListBox Should Be deleted irrespective of the Group name present in the ListBox. can any body help me coding in Pytho

3条回答
  •  一个人的身影
    2020-12-13 01:18

    Here's a great method I recently found on a different stack overflow post regarding multi-dimensional arrays, but the answer works beautifully for single dimensional arrays as well:

    # Create an 8 x 5 matrix of 0's:
    w, h = 8, 5;
    MyMatrix = [ [0 for x in range( w )] for y in range( h ) ]  
    
    # Create an array of objects:
    MyList = [ {} for x in range( n ) ]
    

    I love this because you can specify the contents and size dynamically, in one line!

    One more for the road:

    # Dynamic content initialization:
    MyFunkyArray = [ x * a + b for x in range ( n ) ]
    

提交回复
热议问题