学习笔记之Problem Solving with Algorithms and Data Structures using Python

Problem Solving with Algorithms and Data Structures using Python — Problem Solving with Algorithms and Data Structures

Introduction · python-data-structure-cn

  • https://facert.gitbooks.io/python-data-structure-cn/

Problem Solving with Algorithms and Data Structures Using Python SECOND EDITION: Bradley N. Miller, David L. Ranum: 9781590282571: Amazon.com: Books

  • https://www.amazon.com/Problem-Solving-Algorithms-Structures-Python/dp/1590282574
  • THIS TEXTBOOK is about computer science. It is also about Python. However, there is much more. The study of algorithms and data structures is central to understanding what computer science is all about. Learning computer science is not unlike learning any other type of difficult subject matter. The only way to be successful is through deliberate and incremental exposure to the fundamental ideas. A beginning computer scientist needs practice so that there is a thorough understanding before continuing on to the more complex parts of the curriculum. In addition, a beginner needs to be given the opportunity to be successful and gain confidence. This textbook is designed to serve as a text for a first course on data structures and algorithms, typically taught as the second course in the computer science curriculum. Even though the second course is considered more advanced than the first course, this book assumes you are beginners at this level. You may still be struggling with some of the basic ideas and skills from a first computer science course and yet be ready to further explore the discipline and continue to practice problem solving. We cover abstract data types and data structures, writing algorithms, and solving problems. We look at a number of data structures and solve classic problems that arise. The tools and techniques that you learn here will be applied over and over as you continue your study of computer science.

  • 1.8.2. Built-in Collection Data Types 
Table 3: Methods Provided by Lists in Python
Method NameUseExplanation
appendalist.append(item)Adds a new item to the end of a list
insertalist.insert(i,item)Inserts an item at the ith position in a list
popalist.pop()Removes and returns the last item in a list
popalist.pop(i)Removes and returns the ith item in a list
sortalist.sort()Modifies a list to be sorted
reversealist.reverse()Modifies a list to be in reverse order
deldel alist[i]Deletes the item in the ith position
indexalist.index(item)Returns the index of the first occurrence of item
countalist.count(item)Returns the number of occurrences of item
removealist.remove(item)Removes the first occurrence of item

 

Table 4: Methods Provided by Strings in Python
Method NameUseExplanation
centerastring.center(w)Returns a string centered in a field of size w
countastring.count(item)Returns the number of occurrences of item in the string
ljustastring.ljust(w)Returns a string left-justified in a field of size w
lowerastring.lower()Returns a string in all lowercase
rjustastring.rjust(w)Returns a string right-justified in a field of size w
findastring.find(item)Returns the index of the first occurrence of item
splitastring.split(schar)Splits a string into substrings at schar

 

Table 5: Operations on a Set in Python
Operation NameOperatorExplanation
membershipinSet membership
lengthlenReturns the cardinality of the set
|aset othersetReturns a new set with all elements from both sets
&aset othersetReturns a new set with only those elements common to both sets
-aset othersetReturns a new set with all items from the first set not in second
<=aset <= othersetAsks whether all elements of the first set are in the second

 

Table 6: Methods Provided by Sets in Python
Method NameUseExplanation
unionaset.union(otherset)Returns a new set with all elements from both sets
intersectionaset.intersection(otherset)Returns a new set with only those elements common to both sets
differenceaset.difference(otherset)Returns a new set with all items from first set not in second
issubsetaset.issubset(otherset)Asks whether all elements of one set are in the other
addaset.add(item)Adds item to the set
removeaset.remove(item)Removes item from the set
popaset.pop()Removes an arbitrary element from the set
clearaset.clear()Removes all elements from the set

 

Table 7: Operators Provided by Dictionaries in Python
OperatorUseExplanation
[]myDict[k]Returns the value associated with k, otherwise its an error
inkey in adictReturns True if key is in the dictionary, False otherwise
deldel adict[key]Removes the entry from the dictionary

 

Table 8: Methods Provided by Dictionaries in Python
Method NameUseExplanation
keysadict.keys()Returns the keys of the dictionary in a dict_keys object
valuesadict.values()Returns the values of the dictionary in a dict_values object
itemsadict.items()Returns the key-value pairs in a dict_items object
getadict.get(k)Returns the value associated with kNone otherwise
getadict.get(k,alt)Returns the value associated with kalt otherwise
  • 1.9. Input and Output
    • aName = input('Please enter your name: ')

转载于:https://www.cnblogs.com/pegasus923/p/10454395.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值