List, Dictionary, Set 常用的函数

List

  • list.remove(value), remove the first one equals to the value in list

  • list[index] = list.pop(index), can return or not return, remove by index

  • list.append(value), add the value at the end of this list

  • list.append(sublist[:]), add sublist to the nested list

  • list.extend(list2), flat add list2 to the end of the list

Dictionary

  • for key in dic

  • for key, value in dic.items()

Set

  • set.add(value) 如果要添加的数已存在则无任何操作

  • set.remove(value) 如果要移除的数不存在则报错

  • set.discard(value) 如果要移除的数不存在则无任何操作

Last updated

Was this helpful?