Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lists
- mlist = [1,2,3,4,5,6,7,8] #prints out specified list index, starts at [0]
- print (mlist[1])
- >> 2
- #for in loops saved my life
- mlist = [1,2,3,4,5,6,7,8]
- for x in mlist:
- print (x) #prints list without the ugly square brackets and commas
- #useful list-y things
- .append(value) #appends element to end of the list
- .count('x') #counts the number of occurrences of 'x' in the list
- .index('x') #returns the index of 'x' in the list
- .insert('y','x') #inserts 'x' at location 'y'
- .pop() #returns last element then removes it from the list
- .remove('x') #finds and removes first 'x' from list
- .reverse() #reverses the elements in the list
- .sort() #sorts the list alphabetically in ascending order, or numerical in ascending order
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement