[]
: Lists and indexing/lookup/slicing
- Lists:
[]
,[1, 2, 3]
,[i**2 for i in range(5)]
- Indexing:
'abc'[0]
→'a'
- Lookup:
{0: 10}[0]
→10
- Slicing:
'abc'[:2]
→'ab'
()
: Tuples, order of operations, generator expressions, function calls and other syntax.
- Tuples:
()
,(1, 2, 3)
- Although tuples can be created without parentheses:
t = 1, 2
→(1, 2)
- Although tuples can be created without parentheses:
- Order of operations:
(n-1)**2
- Generator expression:
(i**2 for i in range(5))
- Function or method calls:
print()
,int()
,range(5)
,'1 2'.split(' ')
- with a generator expression:
sum(i**2 for i in range(5))
- with a generator expression:
{}
: Dictionaries and sets
- Dicts:
{}
,{0: 10}
,{i: i**2 for i in range(5)}
- Sets:
{0}
,{i**2 for i in range(5)}
Related Posts:
- FileNotFoundError: [Errno 2] No such file or directory [duplicate]
- python capitalize first letter only
- Is there a short contains function for lists?
- ImportError: No module named pandas. Pandas installed pip
- How to Execute a Python Script in Notepad++?
- ValueError: operands could not be broadcast together with shapes (5,) (30,)
- appending list but error ‘NoneType’ object has no attribute ‘append’
- Using Python 3 in virtualenv
- “Series objects are mutable and cannot be hashed” error
- Putting a simple if-then-else statement on one line [duplicate]
- matplotlib savefig() plots different from show()
- Converting list to numpy array
- How do I parse a string to a float or int?
- No module named MySQLdb
- TypeError: Missing 1 required positional argument: ‘self’
- Convert a tensor to numpy array in Tensorflow?
- How to import the class within the same directory or sub directory?
- Why do I get AttributeError: ‘NoneType’ object has no attribute ‘something’?
- What is __pycache__?
- Permission denied error by installing matplotlib
- Python equivalent of a given wget command
- How to find list intersection?
- Error while Executing jupyter notebook: [Errno 2] No such file or directory
- ValueError: max() arg is an empty sequence
- How do I insert a JPEG image into a python Tkinter window?
- Use a.any() or a.all()
- What is the difference between Spyder and Jupyter?
- What is the maximum recursion depth in Python, and how to increase it?
- subprocess.check_output return code
- How to delete a character from a string using Python
- What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?
- Inverse of a matrix using numpy
- NameError: name ‘self’ is not defined
- gaierror: [Errno 8] nodename nor servname provided, or not known (with macOS Sierra)
- How to print colored text to the terminal
- TypeError: can only concatenate list (not “str”) to list
- What’s the idiomatic syntax for prepending to a short python list?
- What is the difference between “is None” and “== None”
- Why Python 3.6.1 throws AttributeError: module ‘enum’ has no attribute ‘IntFlag’?
- Creating 2D dictionary in Python
- Python: slicing a multi-dimensional array
- Python: pandas merge multiple dataframes
- Shuffle an array with python, randomize array item order with python
- How to count the NaN values in a column in pandas DataFrame
- How to install multiple python packages at once using pip
- Running Selenium with Headless Chrome Webdriver
- How to fix “Attempted relative import in non-package” even with __init__.py
- Errno 13 Permission denied Python
- How to get all possible combinations of a list’s elements?
- Converting strings to floats in a DataFrame
- Pylint “unresolved import” error in Visual Studio Code
- Errno 13 Permission denied Python
- ValueError: object too deep for desired array while using convolution
- How to convert string to binary?
- How to iterate through two lists in parallel?
- Make list of arrays in python
- In Python, what is `sys.maxsize`?
- Pyspark: Exception: Java gateway process exited before sending the driver its port number
- Converting from a string to boolean in Python?
- Import Error: No module named numpy Anaconda
- How to remove \n from a list element?
- Python function overloading
- Breaking out of nested loops
- Youtube_dl : ERROR : YouTube said: Unable to extract video data
- How to stop a function
- What is the common header format of Python files?
- Is it possible to decompile a compiled .pyc file into a .py file?
- Writing string to a file on a new line every time
- Creating lowpass filter in SciPy – understanding methods and units
- Python 2: AttributeError: ‘list’ object has no attribute ‘strip’
- Get Confusion Matrix From a Keras Multiclass Model
- AttributeError: ‘list’ object has no attribute ‘lower’ gensim
- Insert a row to pandas dataframe
- How to get the text cursor position in Windows?
- python NameError: global name ‘__file__’ is not defined
- Rename specific column(s) in pandas
- How to create a numpy array of lists?
- Scikit-learn GridSearch giving “ValueError: multiclass format is not supported” error
- Convert R code into Python code using rpy2
- PIL: DLL load failed: specified procedure could not be found
- “Cannot access setup.py: No such file or directory” – can’t run any .py files?
- How to delete a specific line in a file?
- How does ajax work with python?
- RSA encryption and decryption in Python
- pip3 error – ‘_NamespacePath’ object has no attribute ‘sort’
- can we use XPath with BeautifulSoup?
- how to check which version of nltk, scikit learn installed?
- How do I add two sets?
- How to count the number of files in a directory using Python
- Counting array elements in Python
- IPython, “name ‘plt’ not defined”
- What is the meaning of “int(a[::-1])” in Python?
- Python copy files to a new directory and rename if file name already exists
- How to append new data onto a new line
- Building a list inside a list in python
- ‘pyuic5’ is not recognized as an internal or external command
- ValueError: multiclass format is not supported
- Filtering a NumPy Array
- Invalid syntax when using “print”?
- Installing win32gui python module