3. Python - Lists

 Lists:

listexample = ["hello", 35, 'A']

listexample[0] // returns "hello"

listexample[-1] // returns 'A' at the end


Slicing:

listexample[0:3] // 0,1, and 2 index

listexample[:3] // same as above

listexample[1:-1] // exclude first and last

listexample[1:] // skip first and go to end of list


Functions:

len(listhere) // length of list

sorted(listhere) // sort ABC

sum(listhere) // sums list

max(listhere) // max

min(listhere) // min


List Methods:

listname.append("NEWITEM")

listname.pop() // returns and removes last item of list

listname.index("ITEMTOSEARCH") // returns index of item

"ITEM" in listname // returns false or true if item is in list or not


Tuples: // like list but immutable and uses parenthesis instead

tupletest = (1,2,2,2)

Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort