Dr. Basant Agarwal - Hands-On Data Structures and Algorithms With Python - Store, Manipulate, and Access Data Effectively, 3rd Edition-Packt (2022)
Dr. Basant Agarwal - Hands-On Data Structures and Algorithms With Python - Store, Manipulate, and Access Data Effectively, 3rd Edition-Packt (2022)
https://t.me/prog_books_Pack
BIRMINGHAM—MUMBAI
“Python” and the Python Logo are trademarks of the Python Software Foundation.
Download Packt Books Free
https://t.me/prog_books_Pack
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in
any form or by any means, without the prior written permission of the publisher, except in the case of brief
quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express or
implied. Neither the author nor Packt Publishing or its dealers and distributors, will be held liable for any
damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee
the accuracy of this information.
ISBN 978-1-80107-344-8
www.packt.com
Download Packt Books Free
https://t.me/prog_books_Pack
Contributors
Thank you to Benjamin Baka for his hard work in the first edition.
He’s been working with Python for more than 10 years, focusing on web development using Django.
He’s also the maintainer of Strawberry GraphQL, an open source Python library for creating
GraphQL APIs.
Preface xvii
Logical operators • 17
Tuples • 18
Complex data types ........................................................................................................... 19
Dictionaries • 19
Sets • 23
Immutable sets • 26
Python’s collections module ............................................................................................. 27
Named tuples • 27
Deque • 28
Ordered dictionaries • 29
Default dictionary • 29
ChainMap object • 30
Counter objects • 31
UserDict • 32
UserList • 32
UserString • 33
Summary .......................................................................................................................... 33
Exercises ........................................................................................................................... 55
Arrays ................................................................................................................................ 94
Introducing linked lists ..................................................................................................... 95
Nodes and pointers • 95
Singly linked lists .............................................................................................................. 98
Creating and traversing • 98
Improving list creation and traversal • 99
Appending items • 100
Appending items to the end of a list • 100
Appending items at intermediate positions • 103
Querying a list • 106
Searching an element in a list • 107
Getting the size of the list • 107
Deleting items • 108
Deleting the node at the beginning of the singly linked list • 108
Deleting the node at the end in the singly linked list • 109