-
tuple的功能
查看全部 -
collections模块讲解的内容
查看全部 -
tuple unhashable 可以作为哈希的key(字典key值) tuple可以用*解包方式赋值 *args 传进来作为tuple **kwargs 传进来 key value形式(xx=yy)查看全部
-
hjijojiiojio
查看全部 -
interface查看全部
-
namedtuple查看全部
-
defaultdict namedtuble查看全部
-
ipython查看全部
-
pycharm windows python3.6查看全部
-
Collections查看全部
-
实例: from collections import Counter str_t = "dsjakldjakljdakjdadlkjasdklajkdja" list_t = ['tom', 'tom1', 'tom2', 'tom1', 'tom1', 'tom'] tuple_t = ('tom', 'tom1', 'tom2', 'tom1', 'tom1', 'tom') dict_t = { "tom": "male", "tom1": "male", } print(Counter(str_t)) print(Counter(list_t)) print(Counter(tuple_t)) print(Counter(dict_t.values())) ls_counter = Counter(list_t) ls_counter.update(["tom4"]) print(ls_counter) print(ls_counter.most_common(2))
查看全部 -
实例: from collections import deque list_t = ["tom_l", "jane_l", "bob_l"] tuple_t = ("tom_t", "jane_t", "bob_t") dict_t = { "tom_d": "male", "jane_d": "female", "bob_d": "male" } deq = deque(dict_t) deq.append("tim") deq.appendleft("lewin") deq.extend(tuple_t) deq.extendleft(list_t) deq.popleft() deq.pop() deq.remove("lewin") deq.reverse() print(deq.index("tim")) print(deq)
查看全部 -
实例:
from collections import defaultdict from datetime import datetime def func1(): return None dict_t = {} default_dict = defaultdict(int) key_str = "dskjakdljadakd" for k in key_str: dict_t.setdefault(k, 0) dict_t[k] += 1 default_dict[k] += 1 print("dict_t: {dict_t}\ndefault_dict: {default_dict}".format(dict_t=dict_t, default_dict=default_dict)) ##defaultdict 调用自定义函数 default_dict_custom_func = defaultdict(func1) #defaultdict 调用内置函数 default_dict_sys_func = defaultdict(datetime.now) print("\ndefault_dict_custom_func: {0}\ndefault_dict_sys_func: {1}".format(default_dict_custom_func['func'], default_dict_sys_func['func']))
查看全部 -
实例: from collections import namedtuple key_s = ("name", "age", "gender", "birthday") User = namedtuple("User", key_s) value_s = ("lewin", 29, "male") value_dict = { "name": "tim", "age": 19, "gender": "male" } value_make = ("lily", "18", "female", "2001-02-02") user_tuple = User(*value_s, "1990-01-01") user_dict = User(**value_dict, birthday="2000-02-28") user_make = User._make(value_make) user_order = user_make._asdict() print("user_tuple: {0}\nuser_dict: {1}\nuser_make: {2}\nuser_order: {3}".format(user_tuple, user_dict, user_make, user_order))
查看全部 -
counter 统计功能
查看全部
举报
0/150
提交
取消