Python standard library notes (4)-collections module, pythoncollections
This module provides several very useful Python container types1. Container
Name
Function Description
OrderedDict
Dict that maintains the key Insertion Sequence
Namedtuple
Generate a tuple subclass that can access element content by name
Counter
Counter, mainly used to count
Deque
Similar to a list container, you can
collections are created separately, and the document is inserted. Delete > Db.blogs.remove () // Delete all documents in the collection.
> Db.blogs.remove ({"title": "Hello!"}) // deletes the document for the specified condition, and the current statement deletes "title" as "Hello!" The document. Two, set A collection is a set of documents that corresponds to a data table in a relational database. Dynamic mode The collection is in dynamic
Clojure provides several powerful data structures (collections)I. Types of collections1. VectorEquivalent to an array such as: [2 3 5], ["Ad" "Adas" "Adadsads"]2. ListEquivalent to a linked list, such as: ' (2 3 5), ' ("Ad" "Adas" "Adadsads")Compared to vectors, [] becomes (), and because () the symbol is used for function calls, in order to differentiate, it needs to be preceded by a single quotation mark '3. MapSyntax format such as: {: a 1:b 1}Map
Note that it is not a collection (Interface), but a collection (s cannot be dropped ).The definition of the collections class can be described in one sentence. "This class only provides some static methods (there are actually three constants). These methods can be used to operate on the collection object or return the collection object. "Briefly introduces the methods provided by OSS.The collections class p
A Simple Analysis of the source code of the sort () method in Collections, collectionssort
The sort method code of Collections:
public static Definition of this method: This method is divided into three steps:
(1) Replace list with an object Array
(2) pass this object array to the sort method of the Arrays class (that is to say, the sort of collections act
endindex)Returns a new string that is a substring of this string.
39
Char[] ToCharArray ()This string converts to a new character array.
40
String toLowerCase ()Converts all characters in this string to lowercase by using the default locale's rules.
41
String toLowerCase (Locale Locale)Converts all characters in this string to lowercase using the rule given by the locale.
42
String toString ()This object (this is already a string.) ) itself is returned.
43
String toUpperCase ()Converts all char
Tags: when ... tar explicit IMU one database following BSPMongoDB stores BSON documents, i.e. data records, in collections; The collections in databases. DatabasesIn MongoDB, databases hold collections of documents. To select a database to use, in the MONGO Shell, issue the use statement, as in the following Example Use MyDBCreate a DatabaseIf A database does n
1Import java.util.*; Public classaslist{ Public Static voidMain (String args[]) {//int arr[] = {1,2,3,4,45}; //list//List.add ("QQ"); Cannot be added here, because the length of the array is fixed//integer[] nums = {2,4,5,2}; //list//if the element in the array is an object, then the elements in the array go directly to the elements in the collection when they become collections//if the element in the array is the base data type, the array will be pre
contains a collection and a collectionBetweenthe relationship, also calledSubsetrelationships. Basic meaningis near the same as implication, implication, inclusion,Relationshipadjectives. the inclusions between elements and collections are called elements belonging to the collectionExample a={1,2},b={1,2,3} then 1∈a,2∈a,3∈b belongs to the relationship between the element and the set, for example, element a belongs to collection A, and a∈a belongs to t
This module implements a number of classes, which are very flexible. Can be used to replace Python's built-in dict, list, tuple, set type. And some features are not available for these built-in types.On the network to find some information, focusing on the collections module deque, Counter, Defaultdict class1. Class DequeSimilar to Python's built-in list, but it's a two-way list. Can be manipulated at any endHelp (Collections.deque)Class Deque (__buil
dictionaryKey does not exist, just addKey exists, overwriting the value corresponding to the existing keyIn-place modificationDictionary DeletePop (key[, default])Key exists, removes it, and returns its valueKey does not exist, returns the given defaultDefault is not set, key does not exist throw Keyerror exceptionPopitem ()Removes and returns an arbitrary key-value pairThe dictionary is empty and throws a Keyerror exceptionClear ()Empty dictionaryDictionary traversalFor ... in DictYou can trav
* Tool classes for operating collection and map: Collections--------------------------------------------------------------------------------------------------------------* Reverse (List): Reverses the order of the elements in the listShuffle (list): Randomly sort the elements of a List collectionSort (list): Sorts the specified List collection elements in ascending order based on the natural ordering of the elementsSort (list,comparator): Sorts the Li
) forKvinchret:Print(v,k)#The second wayDic={}with open ("Xx.log","R", encoding="Utf-8") as F: forLineinchF:line=line.split ("/") [2] ifLine not inchDic:data[line]=1Else: Data[line]+=1ret=sorted (Data.items (), key=LambdaX:x[1],reverse=True) forKvinchret:Print(v,k)This topic tests these knowledge points, re module, anonymous function, built-in function sorted,collections in the counterThese can be found in the basic article of the corresponding
Transformations between arrays, collections, strings in Java, and traversal with the enhanced for loop:1 @Test2 Public voidTestDemo5 () {3arraylistNewArraylist();4List.add ("A-B 1");5List.add ("A-B 2");6List.add ("A-B 3");7List.add ("A-B 4");8 // convert the collection to a string and separate it with ",": 9String join = Stringutils.join (list, ",");TenSystem.out.println ("join=" +join); One A // convert the set to an array:
First of all, I would first emphasize that I am a weak chicken farm, this essay is in my study Python3 in the tuple, dictionary, list, set these four kinds of common data types of some feelings, if there is something wrong to welcome everyone to correct. Thank you, everyone.Back to the point: This essay discusses lists, dictionaries, tuples, and collections. Therefore, it is necessary to make a brief analysis of three kinds of data types first:1: List
is, the List is rearranged based on the input of the random source, which has the same probability (assuming that the random source is fair). This algorithm is very useful in implementing a game of chance. For example, it can be used to mix a List of card objects that represent a deck of cards. In addition, it is also useful when generating test cases.Collections.shuffling (list)4) Inversion (Reverse)Use the reverse method to sort the specified list in descending order based on the natural orde
TreeSet and TreeMap sorting when comparing elements require element objects to implement comparable interfacesThere are two ways to compare elements in the collections sort method:Element object implementation comparable interfaceEntity class Dog1 Public classDogImplementsCloneable,comparable {2 3 PrivateString name;4 PrivateString age;5 6 PublicString GetName () {7 returnname;8 }9 Public voidsetName (String name) {T
* 2. Variable parameter, must be written in the last one of the parameter list */public static void function (OBJECT...O) { }/* * Definition method, calculates the variable parameter implementation of 10 integers and * methods */public static int get Sum (int ... a) {int sum = 0; for (int i:a) {sum = sum + i;} return sum;}}Third, collections--collection implementation classAre all under the list implementation class1. Sorting/* * collections.sort s
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.