#arrays Searching Sorting myList=["Oranges","Apples","Bananas","Limes","Peaches","Strawberries","Kiwi","Pears"] print(myList[2]) myList[3]="Lemons" print(myList[3]) #iterating through the array (list) for i in range(0,len(myList)): print(myList[i]) print("********************************************************************************************") myList.sort() for nextItem in myList: print(nextItem) myCustomers = [[0 for row in range(4)] for column in range(6)] myCustomers[0][0] = "Greg J" myCustomers[0][1] = 730 myCustomers[0][2] = 45 myCustomers[0][3] = "Male" myCustomers[1][0] = "Bob S" myCustomers[1][1] = 672 myCustomers[1][2] = 32 myCustomers[1][3] = "Male" myCustomers[2][0] = "Jill M" myCustomers[2][1] = 755 myCustomers[2][2] = 28 myCustomers[2][3] = "Female" myCustomers[3][0] = "Liz K" myCustomers[3][1] = 700 myCustomers[3][2] = 19 myCustomers[3][3] = "Female" myCustomers[4][0] = "JR S" myCustomers[4][1] = 550 myCustomers[4][2] = 59 myCustomers[4][3] = "Male" myCustomers[5][0] = "Ken J" myCustomers[5][1] = 775 myCustomers[5][2] = 26 myCustomers[5][3] = "Male" print(myCustomers[5]) #Nested Lists ListOfFoods = [["Oranges","Apples","Pears","Peaches"],["Beef","Pork","Chicken","Turkey","Fish"]] print(ListOfFoods[0][1]) ListOfFoods.append(["Peas","Beans","Lettuce","Carrots","Celery"]) print(ListOfFoods[2][0]) ListOfFoods[1].append("Venison") print(ListOfFoods[1]) MyEmployeeList = [["Greg J","12345","1111","M"], ["Jan S","00987","8763","F"], ["Ken S","12345","1111","M"], ["Jill J","87102","4342","F"], ["Bill W","90489","9843","M"] ] print(MyEmployeeList[0][0]) MyEmployeeList[2][1] = "55576" print(MyEmployeeList[2]) #bubble sort the list of Employees SwapPerformed = True while(SwapPerformed): SwapPerformed=False temp="" for indx in range(1,len(MyEmployeeList)): if(MyEmployeeList[indx][0] < MyEmployeeList[indx-1][0]): temp=MyEmployeeList[indx][0] MyEmployeeList[indx][0] = MyEmployeeList[indx-1][0] MyEmployeeList[indx-1][0]=temp SwapPerformed=True print(MyEmployeeList) # myList = [99,32,17,104,3,78,105,51,9,43,57,79,42] i=0 j=0 iMin=0 for indxUnsorted in range(0,len(myList)): iMin = indxUnsorted; for indxSorted in range(indxUnsorted+1,len(myList)): if (myList[indxSorted] < myList[iMin]): iMin = indxSorted; if(iMin != indxUnsorted): tmp = myList[indxUnsorted] myList[indxUnsorted] = myList[iMin] myList[iMin] = tmp print(myList)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question