Hi method in Python-day3 list, python-day3hi
1. Create a list object correctly
Li = list ([1, 2, 4])Li2 = list (1, 2, 3, 4 ))
2. append
Result = li. append (5)
3. clear
Result = li. clear ()
4. Copy --- 1. Shallow copy and
Python implements the nested list and dictionary and repeats the function example by a certain element. python nesting
This example describes how to implement a nested list and dictionary in Python and repeat the function by a certain element. We will share this with you for
In the interview process of the Python-related position, the list of lists will be inspected. (Note that it is sometimes required to ensure that the order of the heavy )1. Intuitive method1 li=[1,2,3,4,5,1,2,3]2 new_li=[]3 for in Li: 4 if not in new_li:5 new_ Li.append (i)6print(new_li)First create a new empty list, by traversing the original
map function:
Prototype: Map (function, sequence), which is to map a list to another list,
How to use:
def f (x):
Return x**2
L = Range (1,10)
Map (f,l)
OUT[3]: [1, 4, 9, +, BA] reduce function
Prototypes: Reduce (function, sequence, startvalue), which is to generalize a list into one output,How to use:
def f2 (x,y):
Return X+y
Reduce (f1,l)
OUT[7]: 45
Reduce (f
, [], None]) # is there any one element equal to the true valueSorted ([1,5,3]) # Returns the sequence of the positive sequence, i.e. [1,3,5]Reversed ([1,5,3]) # Returns the sequence of the reverse order, i.e. [3,5,1]Class, Object, property# define ClassClass Me (object): def Test (self): print "hello!"Def new_test ():Print "New hello!"me = Me ()Hasattr (Me, "Test") # Check if the Me object has a test propertyGetAttr (Me, "test") # Returns the Test propertySetAttr (Me, "test", New_test
Full-stack python development-Day4 list, python development-day4Full-stack python development-Day4 listI. First, expand the learning list based on the following points:
#1: Basic use 1 Purpose 2 definition method 3 common operations + Built-in method #2: this type of Summary
Sharing of Python list generator's cycle skills, python Generator
The List generator is list Comprehensions, which is a simple but powerful built-in form that can be used to create a List.
One cycle
In other languages such as C
Python Filter list usage instance analysis, python usage instance analysis
This example describes how to use Python to filter lists. We will share this with you for your reference. The details are as follows:
Filter list
[Mapping-expression for element in source-
The derivation of comprehensions (also known as analytic) is a unique feature of Python. Derivation is the structure of another new data series that can be built from one data series.
List-derived
Dictionary (dict) derivation formula
Set (set) derivation
List derivation one, use [] to generate listBasic format for inch if the conditio
What is a list: lists allow you to store groups of information in one place, which can contain several elements or millions of elements. The list is one of the lightest Python features that novices can use directly, and it incorporates the concepts of many important programming.List definition: A list consists of a ser
Python learning-1 List for simple shopping cart, python-1
Product_list = [('iphone ', 8000 ),('Bike', 1000 ),('Car ', 200000 ),('Two', 50000)]Shop_list = []For I, v in enumerate (product_list ):Print (I, v)While True:Money = input ("Enter your money :")If money. isdigit ():Money = int (money)While True:Choice = input ("Enter the product serial number and exit the
, 2,-4, 2])# Minimum value
Sum ([2,-1, 9, 12])# Sum
Type conversion
INT ("5 ")# Convert to integer
Float (2)# Converting to float
Long ("23 ")# Convert to a long integer
STR (0, 2.3)# Convert to string
Complex (3, 9)# Return the plural 3 + 9i
Ord ("")# Value corresponding to the "A" Character
CHR (65)# Characters corresponding to the value 65
Unichr (65)# Unicode characters corresponding to the value 65
Bool (0)# Convert to the corresponding real value. In
Like a single-linked list, it just adds a pointer to the previous element.:Python implementation code:#Personal Python Data Structure--ppds##!/usr/bin/python#-*-coding:utf-8-*-classNode (object):def __init__(self,val,p=0): Self.data=Val Self.next=P Self.prev=Pclasslinklist (object):def __init__(self): Self.head=0defini
Flip linked list of Python data structure and flip of python Data Structure
Flip a linked list
Example: A chain table 1-> 2-> 3-> null. The flipped chain table is 3-> 2-> 1-> null.
A simple method is to use the "removal" method ". It is to first create an empty node, then traverse the entire linked
on an existing listFormat: [expression for iter_val in iterable]# each item in the list takes square li = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]li2 = [i**2 for i in Li]print (' li2 =%s '% li2) # output: Li2 = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]# only a number greater than 5 takes the square. An expression can also be an if statement li = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]li2 = [i**2 If i > 5 else I for I in li]print (' li2 =%s '% li2) # output: Li2 = [0, 1, 2,
quotation marks for multi-line strings, or multiline commentsJob 1Jump out of the multilayer loop, three-layer cycle, the innermost layer, jumping out of 3 layers,Job 2Shopping Cart Program (knowledge points, loops, lists,)python shopping.pyInput your salary:5000you can buy the following things:1.iphone 58002.coffee3.book4.condom>>: 1can't afford to print, how much is the difference?>>:2can afford to put into the shopping cart, deduct money, while pr
Python ing list learning and python ing
List ing is a very useful method. By applying a function to each element in the list to convert data, you can use a policy or method to traverse and compute each element.
For example:
?
12345678910111213141516171819202122232
List Comprehensions provide a concise-to-create new lists, where each item was the result of an operation applied to EA CH member of an existing list, dictionary or other iterable. Learn how to create your own list comprehensions on this lesson.Sales = [3.14, 7.99, 10.99, 0.99, 1.24 for in sales]With Condiion:Zoo_animals = ['Giraffe','Monkey','Elephant','Lion','
3rd Chapter Learning Goals:
What the list is and how to use the list element. Lists allow you to store groups of information in one place, which can consist of just a few elements or millions of elements. The list is one of the most powerful Python features that novices can use directly, and it incorporates a
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.