Welcome to visit 'python-NOTes' category in LuCima's SpaCe. Here gathers several posts summerized advanced usages, tips and black techs about Python. All contents are based on Python 3.x, though Python 2.x may be referred to shortly.
read moreOther articles
Operaions on Basic data structure -- dict
Series of posts (2)
If you want to build up a dict using two lists,
zip()
can be used as this:
dict(zip(list_a, list_b))
Sometimes,
read moreOrderedDict
andDefaultDict
in modulecollections
can be useful. When you need a dict whose keys areOperaions on Basic data structure -- list
Series of posts (1)
Here I am going to summarize some advancing operations about list, which is one of the most commonly used data structure in Python. Basic usage of list will be skipped.
The built-in function
read moresorted()
is helpful for sorting the list or …Operations on FILE and PATH
This post is going to introduce Python's' operations upon files and paths in OS. The most commonly used modules are
read moreos.path
andshutil
.How to implement User Datagram Protocol with Python RAW socket
one’s complement in UDP
- Construct the UDP header and UDP Pseudo header, as illustrated below, where Checksum is set zero at first.
- Check the length of data, if it is an odd length of bytes, supplement a byte of zero (0x00) at the end of the data when counting …
One application of yield
When you want to generate an iterable letter list such as ['A', 'B', ..., 'J'], using
yield
will be very graceful.
An example is listed below:read moredef letter_increment(letter): assert len(letter) == 1 return chr(ord(letter) + 1) def iter_letter(start_letter='A', end_letter='J'): current_letter = start_letter while True: yield current_letter if …