TAILIEUCHUNG - Advance Praise for Head First Python Part 5

Ngoài ra các danh sách, Python cũng đi kèm với thiết lập cấu trúc dữ liệu, mà ứng xử như các bộ bạn đã học được tất cả về lớp học toán. Các đặc điểm bao trùm của bộ trong Python rằng các mục dữ liệu trong tập hợp có thứ tự và các bản sao không được phép. | comprehending data Wouldn t it be dreamy if there were a way to quickly and easily remove duplicates from an existing list But I know it s just a fantasy. you are here 4 165 factory functions Remove duplicates with sets In addition to lists Python also comes with the set data structure which behaves like the sets you learned all about in math class. The overriding characteristics of sets in Python are that the data items in a set are unordered and duplicates are not allowed. If you try to add a data item to a set that already contains the data item Python simply ignores it. Create an empty set using the set BIF which is an example of a factory function Create a hew set and assijh i-t -to a variable. distances set It is also possible to create and populate a set in one step. You can provide a list of data values between curly braces or specify an existing list as an argument to the set BIF which is the factory function dupliea-tes ih the supplied list data values are ignored- distances 11 8 two 7 Any duyUates in he james hst a re inhered- Cool- distances set james r fefer s toner Factory Function A factory function is used to make new data items of a particular type. For instance set is a factory function because it makes a new set. In the real world factories make things hence the name. 166 Chapter 5 comprehending data Tonight s talk Does list suffer from set envy List sings Anything you can do I can do better. I can do anything better than you. Can you spell d-a-t-a l-o-s-s Getting rid of data automatically sounds kinda dangerous to me. Seriously And that s all you do And they pay you for that Have you ever considered that I like my duplicate values. I m very fond of them you know. Which isn t very often. And anyway I can always rely on the kindness of others to help me out with any duplicates that I don t need. Set I m resisting the urge to say No you can t. Instead let me ask you what about handling duplicates When I see them I throw them away .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.