While coding using Python, I will leave what I searched for as "Oh, how do I do this process" in this post as a memorandum for myself. Will be updated from time to time.
dict.keys()
dict.values()
By the way, a list that includes both keys and values
dict.items()
dict[New key] =value
dict[Key] =value
dict[Key] += 1
del dict[Key]
An element in list
list.index(An element)
list.append(An element) # リストの末尾にAn elementを追加
list.insert(0,An element) #Add the element at the top of the list (change 0 to insert the element at the corresponding position)
list = str.split(' ') #This decomposes str with whitespace and creates a list with each as an element of the list.
list = [0] * n
list.reverse()
"".join(list) # ""If you put a specific symbol inside, that character is put in between and connected
map(str, list)
del(list[index]) #Delete element
list.pop(index) #This is a cut, so
list1.append(list2.pop()) #You can add the last element of list2 to the end of list1
#By the way, pop()If no argument is specified for, the last element is targeted.
list = [i for i in range(10)]
list = [i for i in range(10) if i % 2 == 0] #In addition, if statements can be included
import collections
list = ['a', 'b', 'c', 'b', 'd', 'a']
counter = collections.Counter(list) # -> {'a':2, 'b':2, 'c':1, 'd':1}
sorted(list) #Sort the elements in the list in ascending order
sorted(dict.keys()) #Sort the dictionary in ascending key order
sorted(dict.items(), key=lambda x:x[1]) #Sort the dictionary in ascending order of value
sorted(list, reverse=True) #Just assign True to the reverse argument
count = 0
def add_count():
global count #Access variables defined outside the function and
#Add global to apply the change outside the function
count += 1
Recommended Posts