This section provides practical code snippets for various common programming tasks, serving as a quick reference guide.
- Adopt square bracket []
# Empty list
ops_empty = []
print(ops_empty) # []
# List of whole numbers
nums = [20, 8, 2002]
print(nums) # [20, 8, 2002]
# List of well-known car manufacturers
manufacturers = ["Honda", "Cadillac", "Volkswagen Beetle", "TOYOTA"]
print(manufacturers) # ["Honda", "Cadillac", "Volkswagen Beetle", "TOYOTA"]- Use list() constructor
# Empty list
ops_empty = []
print(ops_empty) # []
# Transform the name of Elon Musk to a list of characters
chrs = list("Elon Musk")
print(chrs) # ['E', 'l', 'o', 'n', ' ', 'M', 'u', 's', 'k']# Go through each neighborhoods' house and give a greet
intimate_neighborhoods = ["Phương", "Anh", "Lâm", "Khoa"]
for neighborhood in intimate_neighborhoods:
print(f"🙋 Hi {neighborhood}. Have a good day!")🙋 Hi Phương. Have a good day !
🙋 Hi Anh. Have a good day!
🙋 Hi Lâm. Have a good day!
🙋 Hi Khoa. Have a good day!# Declare a list of well-known scientists
scientists: list[str] = ["Issac Newton", "Albert Einstein", "Niels Bohr", "Michael Faraday", "Max Born", "Johannes Kepler"]
# Arrange elements in ascending order
print(sorted(scientists))
# Rearrange items in descending order
print(sorted(scientists, reverse=True))['Albert Einstein', 'Issac Newton', 'Johannes Kepler', 'Max Born', 'Michael Faraday', 'Niels Bohr']
['Niels Bohr', 'Michael Faraday', 'Max Born', 'Johannes Kepler', 'Issac Newton', 'Albert Einstein']This section contains examples of regular expressions question to practice and solutions.
This section provides a dedicated collection of algorithm problems I've successfully navigated. Consider this a practical reference for your coding interview preparation.
This project is distributed under MIT License. See License.txt for more details.
