Python: Tudo o que você tinha vergonha de perguntar
January 06, 2020Python Basic cheatsheet for Python mostly based on the book written by Al Sweigart, Automate the Boring Stuff with Python under the Creative…
Está curtindo os conteúdos da Reativa? Quer que a gente te ajude a ser um dev melhor? Deixe seu melhor email aqui.
Python Basic cheatsheet for Python mostly based on the book written by Al Sweigart, Automate the Boring Stuff with Python under the Creative…
Glossary of Generator Produce value via generator Unpacking Generators Implement Iterable object via generator Send message to generator…
Set comprehension Uniquify a List Union Two Sets Append Items to a Set Intersection Two Sets Common Items from Sets Contain b contains a a…
============== is a function New in Python 3.0 PEP 3105 - Make print a function Python 2 Python 3 String is unicode New in Python 3.0 PEP…
Simple https server Generate a SSH key pair Get certificate information output: Generate a self-signed certificate output: Prepare a…
A simple Python unittest Python unittest setup & teardown hierarchy output: Different module of setUp & tearDown hierarchy output: Run tests…
A function can help programmers to wrap their logic into a task for avoiding duplicate code. In Python, the definition of a function is so…
Read a File In Python 2, the content of the file which read from file system does not decode. That is, the content of the file is a byte…
Future statements tell the interpreter to compile some semantics as the semantics which will be available in the future Python version. In…
Occasionally, it is unavoidable for pythoneers to write a C extension. For example, porting C libraries or new system calls to Python…
Naming Class Bad Good Function Bad Good Variable Bad Good Acesse a Referência original 1: Acesse a Referência original 2:
PEP 484, which provides a specification about what a type system should look like in Python3, introduced the concept of type hints. Moreover…
Set a database URL output: Sqlalchemy Support DBAPI - PEP249 Transaction and Connect Object Metadata - Generating Database Schema Inspect…
======= asyncio.run New in Python 3.7 Future like object Future like object other task Patch loop runner Put blocking task into Executor…
============ The main goal of this cheat sheet is to collect some common and basic semantics or snippets. The cheat sheet includes some…
================== Compare HTML tags tag type format example all tag…
Login ssh Acesse a Referência original 1: Acesse a Referência original 2:
The list is a common data structure which we use to store objects. Most of the time, programmers concern about getting, setting, searching…
List Attributes Get Instance Type Declare a Class Equals to Has / Get / Set Attributes Check Inheritance Get Class Name New and Init will…
Get All Keys Get Key and Value Find Same Keys Set a Default Value returns its default value if key is not in the dictionary. However, if…
The main goal of this cheat sheet is to collect some common snippets which are related to Unicode. In Python 3, strings are represented by…
Execute a shell command Create a thread via “threading” Performance Problem - GIL Consumer and Producer Thread Pool Template Using…
Socket programming is inevitable for most programmers even though Python provides much high-level networking interface such as httplib…
Returns the average of a list, after mapping each element to a value using the provided function. Use to map each element to the value…
Returns if the provided function returns for every element in the list, otherwise. Use in combination with and to check if returns…
Returns the minimum elements from the provided list. If is greater than or equal to the provided list’s length, then return the original…
Capitalizes the first letter of every word in a string. Use to capitalize first letter of every word in the string. Acesse a Referência…
Returns all the elements of a list except the last one. Use to return all but the last element of the list. Acesse a Referência original…
Returns the minimum value of a list, after mapping each element to a value using the provided function. Use with to map each element to a…
Casts the provided value as a list if it’s not one. Use to check if the given value is enumerable and return it by using or encapsulated…
Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters). Use to remove…
Returns the sum of a list, after mapping each element to a value using the provided function. Use with to map each element to a value…
Calculates the factorial of a number. Use recursion. If is less than or equal to , return . Otherwise, return the product of and the…
Converts an angle from degrees to radians. Use and the degrees to radians formula to convert the angle from degrees to radians. Acesse a…
Returns the maximum elements from the provided list. If is greater than or equal to the provided list’s length, then return the original…
Returns a flat list of all the values in a flat dictionary. Use to return the values in the given dictionary. Return a of the previous…
Returns the last element in a list. use to return the last element of the passed list. Acesse a Referência original 1: Acesse a Referência…
Returns if all the values in a list are unique, otherwise. Use on the given list to remove duplicates, use to compare its length with…
Initializes and fills a list with the specified value. Use list comprehension and to generate a list of length equal to , filled with the…
Returns a list of elements that exist in both lists. Use list comprehension on to only keep values contained in both lists. Acesse a…
Splits values into two groups according to a function, which specifies which group an element in the input list belongs to. If the function…
Flattens a list of lists once. Use nested list comprehension to extract each value from sub-lists in order. Acesse a Referência original…
Curries a function. Use to return a new partial object which behaves like with the given arguments, , partially applied. Acesse a…
Performs left-to-right function composition. Use to perform left-to-right function composition. The first (leftmost) function can accept…
Given a list, returns the items that are parity outliers. Use with a list comprehension to count even and odd values in the list, use to…
Returns the average of two or more numbers. Use to sum all of the provided, divide by . Acesse a Referência original 1: Acesse a…
Returns every element that exists in any of the two lists once. Create a with all values of and and convert to a . Acesse a Referência…
Returns the maximum value of a list, after mapping each element to a value using the provided function. Use with to map each element to a…
Capitalizes the first letter of a string. Capitalize the first letter of the string and then add it with rest of the string. Omit the…
Returns the unique elements in a given list. Create a from the list to discard duplicated values, then return a from it. Acesse a…
Finds the median of a list of numbers. Sort the numbers of the list using and find the median, which is either the middle element of the…
Generates a list, containing the Fibonacci sequence, up until the nth term. Starting with and , use to add the sum of the last two numbers…
Given a predicate function, , and a string, this curried function will then take an object to inspect by calling the property and passing…
Converts a string to kebab case. Break the string into words and combine them adding as a separator, using a regexp. Acesse a Referência…
Clamps within the inclusive range specified by the boundary values and . If falls within the range, return . Otherwise, return the…
Converts a number to a list of digits. Use combined with on the string representation of and return a list from the result. Acesse a…
Performs right-to-left function composition. Use to perform right-to-left function composition. The last (rightmost) function can accept…
Decapitalizes the first letter of a string. Decapitalize the first letter of the string and then add it with rest of the string. Omit the…
Filters out the unique values in a list. Use a to get the count of each value in the list. Use list comprehension to create a list…
Randomizes the order of the values of an list, returning a new list. Uses the Fisher-Yates algorithm to reorder the elements of the list…
Groups the elements of a list based on the given function and returns the count of elements in each group. Use to map the values of the…
Returns the index of the element with the maximum value in a list. Use and to get the maximum value in the list and return its index…
Returns if the given string is a palindrome, otherwise. Use and to convert to lowercase and remove non-alphanumeric characters from the…
Checks if the given number falls within the given range. Use arithmetic comparison to check if the given number is in the specified range…
Groups the elements of a list based on the given function. Use and to map the values of the list to the keys of an object. Use list…
Flattens a list, by spreading its elements into a new list. Loop over elements, use if the element is a list, otherwise. Acesse a…
Returns the head of a list. Use to return the first element of the passed list. Acesse a Referência original 1: Acesse a Referência…
Checks if the first numeric argument is divisible by the second one. Use the modulo operator () to check if the remainder is equal to…
Returns the length of a string in bytes. Use to encode the given string and return its length. Acesse a Referência original 1: Acesse a…
Returns the transpose of a two-dimensional list. Use to get the passed list as tuples. Use in combination with to create the transpose of…
Removes falsey values from a list. Use to filter out falsey values (, , , and ). Acesse a Referência original 1: Acesse a Referência…
Prints out the same string a defined number of times. Repeat the string times, using the operator. Acesse a Referência original 1: Acesse…
Converts an angle from radians to degrees. Use and the radian to degree formula to convert the angle from radians to degrees. Acesse a…
Returns a random element from a list. Use to generate a random number that corresponds to an index in the list, return the element at that…
Returns the symmetric difference between two iterables, without filtering out duplicate values. Create a from each list, then use list…
Moves the specified amount of elements to the end of the list. Use and to get the two slices of the list and combine them before returning…
Creates an object with the same keys as the provided object and values generated by running the provided function for each value. Use to…
Returns if the given number is odd, otherwise. Checks whether a number is even or odd using the modulo () operator. Returns if the…
Checks if all elements in a list are equal. Use and to compare all the values in the given list. Acesse a Referência original 1: Acesse a…
Takes any number of iterable objects or objects with a length property and returns the longest one. If multiple objects have the same…
Returns if the given number is even, otherwise. Checks whether a number is odd or even using the modulo () operator. Returns if the…
Splits a multiline string into a list of lines. Use and to match line breaks and create a list. provides similar functionality to this…
Returns the difference between two lists, after applying the provided function to each list element of both. Create a by applying to each…
Returns the reverse of a string. Use string slicing to reverse the string. Acesse a Referência original 1: Acesse a Referência original 2:
Returns a flat list of all the keys in a flat dictionary. Use to return the keys in the given dictionary. Return a of the previous result…
Returns a list of elements that exist in both lists, after applying the provided function to each list element of both. Create a by…
Initializes a list containing the numbers in the specified range where and are inclusive with their common difference . Use and to…
Invokes the provided function after milliseconds. Use to delay the execution of by seconds. Acesse a Referência original 1: Acesse a…
Deep flattens a list. Use recursion. Use with to check if an element is iterable. If it is, apply recursively, otherwise return . Acesse…
Builds a list, using an iterator function and an initial seed value. The iterator function accepts one argument () and must always return a…
Counts the occurrences of a value in a list. Increment a counter for every item in the list that has the given value and is of the same type…
Splits values into two groups. If an element in is , the corresponding element in the collection belongs to the first group; otherwise, it…
Returns a list of elements that exist in both lists. Create a from and , then use the built-in set operator to only keep values contained…
Returns if the provided function returns for at least one element in the list, otherwise. Use in combination with and to check if…
Returns every nth element in a list. Use to create a new list that contains every nth element of the given list. Acesse a Referência…
Initializes a 2D list of given width and height and value. Use list comprehension and to generate rows where each is a list with length…
Returns the difference between two iterables. Create a from , then use list comprehension on to only keep values not contained in the…
Returns the most frequent element in a list. Use to get the unique values in the combined with to find the element that has the most…
Filters out the non-unique values in a list. Use a to get the count of each value in the list. Use list comprehension to create a list…
Returns the least common multiple of a list of numbers. Use , and over the given list. Acesse a Referência original 1: Acesse a Referência…
Converts a string to camelcase. Use to replace any or with a space, using the regexp . Use to capitalize the first letter of each word…
Chunks a list into smaller lists of a specified size. Use and to create a list of the desired . Use on the list and fill it with splices…
Returns all elements in a list except for the first one. Return if the list’s length is more than , otherwise, return the whole list…
Converts a string to snake case. Break the string into words and combine them adding as a separator, using a regexp. Acesse a Referência…
Returns if there are duplicate values in a flat list, otherwise. Use on the given list to remove duplicates, compare its length with the…
Returns every element that exists in any of the two lists once, after applying the provided function to each element of both. Create a by…
Calculates the greatest common divisor of a list of numbers. Use and over the given list. Acesse a Referência original 1: Acesse a…
Tests a value, , against a function, conditionally applying a function. Check if the value of is and if so return , otherwise return…
Returns if the provided function returns for at least one element in the list, otherwise. Use and to check if returns for all the…
Creates a list of elements, grouped based on the position in the original lists. Use combined with to get the length of the longest list…
Returns the symmetric difference between two lists, after applying the provided function to each list element of both. Create a by applying…