Minor improvements

Just made some things clearer by comments.
This commit is contained in:
Michael Hienle 2018-07-20 16:40:38 +02:00 committed by GitHub
parent a66ea66c80
commit 15a7a7e126
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 10 deletions

View File

@ -6,17 +6,17 @@ title: Python
list = [] list = []
list[i:j] # returns list subset list[i:j] # returns list subset
list[-1] # access last element list[-1] # returns last element
list[:-1] # return all but the last element list[:-1] # returns all but the last element
list[i] = val list[i] = val
list[i:j] = otherlist # replace ith to jth element with otherlist list[i:j] = otherlist # replace ith to jth element with otherlist
del list[i:j] del list[i:j]
list.append(item) list.append(item)
list.extend(list) list.extend(another_list)
list.insert(0, item) list.insert(0, item)
list.pop() list.pop() # returns and removes last element from the list
list.remove(i) list.remove(i)
list1 + list2 # combine two list list1 + list2 # combine two list
set(list) # remove duplicate elements from a list set(list) # remove duplicate elements from a list
@ -25,19 +25,19 @@ title: Python
list.count(item) list.count(item)
sum(list) sum(list)
list.sort() list.sort() # sorts in-place, returns None
zip(list1, list2) zip(list1, list2)
sorted(list) sorted(list) # returns sorted copy of list
",".join(list) ",".join(list) # returns a string with list elements seperated by comma
### Dict ### Dict
dict.keys() dict.keys()
dict.values() dict.values()
"key" in dict "key" in dict # let's say this returns False, then...
dict["key"] # throws KeyError dict["key"] # ...this raises KeyError
dict.get("key") dict.get("key") # ...this returns None
dict.setdefault("key", 1) dict.setdefault("key", 1)
### Iteration ### Iteration