Skip to main content

Posts

AD

Multi-dimensional Array

In Python, a multi-dimensional array (or list) is essentially a list of lists (or a list of lists of lists, etc.). These are useful for representing more complex data structures, like matrices or grids. For example, a 2D array (like a table) can be created as a list of lists. Here’s a quick guide: Creating a 2D Array

Python Frameworks

What is a framework? A framework in programming refers to a pre-built structure or set of tools that developers use to create software applications. It provides a foundation that developers can build upon, allowing them to focus on the specific logic and functionality of their application rather than the low-level details of coding everything from scratch. Frameworks often include libraries, APIs, and other components that streamline the development process by providing common functionalities like database access, user authentication, and web services integration. Frameworks are designed to promote best practices, maintainability, scalability, and efficiency in software development. There are many frameworks available in Python but we will talk about some famous of them. Django Flask Pyramid CherryPy Tornado Let's get some overview of all frameworks here: Django : A high-level web framework that provides rapid development and clean, robust design. It includes many useful built-in...

Python List

What is a List? List is a data type in Python. List is used to store multiple values ( it can string, integer, float and other lists also ) in a single variable. Lists are mutable, which means you can modify, add, and remove elements from them. We can define a list in the following ways, 1. myList = [value1, value2, value3] 2. myTuple = (value1, value2, value3) myTupleList = list(myTuple) 3. myStr = 'My String' myStrList = list(myStr)  Example: a = [1,2,3] print(a) Output: [1,2,3] You can access individual elements in a list using square brackets and the index of the element. Indexing starts from 0 in the Python List. Like we want to access the third element of the above example list, we can write, a[2] Output: 3 If we want a string in a list, we will use double quotes for the element. Also if we want to use a list in the list we can use it. Example: myList = [2,4, ["a", 4]] myList[2] Output: ["a", 4] List can have duplicate elements. We can add, remove ...

Data Types

We can identify the type of data/variable based on value. It indicates which type of data that you are using like string, integer, float or other. Data types are classifications of data items, indicating the kind of values they can hold and the operations that can be performed on them. In programming and computer science, data types are crucial because they determine the structure of data and the ways in which it can be manipulated. In Python, data types are dynamically inferred, meaning you don't need to explicitly declare the type of a variable. Python automatically determines the data type based on the value assigned to it. List of Data Types: Name Keyword Example Integer int a = 2 Float float b = 1.2 String str name = "John" Boolean bool is_valid = True List list numList = [10,20,30,40, 50] ...

Best IDEs for Python Programming

5 Best IDEs for Python Programming Today, there are many IDEs available in the market. I tried many of them, but some have fabulous features to enjoy while programming in those IDEs.  I will give you some of the best IDEs for you that boost your writing efficiency as well as save you time. You can use it as per your requirements and flexibility. Here is the list of top 5 python editor: 1. PyCharm 2. Eclipse 3.  Visual Studio Code 4. Spyder 5.  Sublime Text Let's begin to clear your confusion to choose the best. 1. PyCharm PyCharm is a popular integrated development environment (IDE) used primarily for Python development. Developed by JetBrains, it provides a robust set of features for writing, debugging, and deploying Python code. PyCharm offers features such as code completion, syntax highlighting, debugging tools, version control integration, and support for various frameworks and libraries. PyCharm offers comprehensive support for web development with Python, incl...

Lambda Function

A lambda function is a small and anonymous function. "Anonymous function is a function without a name". We can define this function using lambda keyword.

Title Operation Function : Making Title as Slug

Example >> INPUT : myStr = "Legal Counsel 3 - 8 yrs' PQE"  >>  CODE : import re def apply_operation(title): title = unicode(title.lower().strip()) // if not work so just remove unicode title = title.replace('&','') title = re.sub(r'(?s)\s+', r'-', title) title = re.sub(r"(?s)[^a-z-0-9]",r"-", title) title = re.sub(r'(?s)\-{2,}', r'-', title)           return title result = apply_operation(myStr) print(result) >>  OUTPUT : legal-counsel-3-8-yrs-pqe >>  Additional Note : Add the following code if you want to convert non-english to english characters  with "import unicodedata" module. unicodedata.normalize('NFKD', title).encode('ASCII', 'ignore')

String Replace using List method

Example >> INPUT : myStr  = " https://pythonsmallsoultions.blogspot.com/?lang=en&page=0&pageSize=10" myStr_list = myStr.split("&") myStr_list[1] = 'page='+str(1) myStr = "&".join( myStr_list ) >> OUTPUT : https://pythonsmallsoultions.blogspot.com/?lang=en&page1&pageSize=10

Useful User-Agent List

Here is the full list of User-Agents Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1064 Safari/532.5 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.94 Chrome/37.0.2062.94 Safari/537.36 Mozilla/5.0 (Windows NT 5.1)  Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) Mozilla/5.0 (compatible; Bingbot/2.0; +http://www.bing.com/bingbot.htm) Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)  Chrome/52.0.2743.116  Chrome/60.0.3112.113 Googlebot/2.1 Google Chrome curl/7.29.0 curl/7.37.1 curl/7.69.1 python-requests/2.26.0 Wget/1.21.1 Sla...

Iterator

In Python, an iterator is an object that allows you to traverse through a collection of elements, such as lists, tuples, or dictionaries, one at a time. Iterators provide a way to access elements sequentially without needing to know the underlying implementation of the data structure. An iterator must implement two methods: 1. __iter__(): This method returns the iterator object itself. It is called when you use the `iter()` function on the iterator. 2. __next__() : This method returns the next item in the iterator. It is called repeatedly to fetch the next element in the sequence. When there are no more elements to return, it raises the ' StopIteration ' exception. Here's an example to illustrate how iterators work: class MyIterator:     def __init__(self, data):         self.data = data         self.index = 0     def __iter__(self):         return self     def __next__(self):     ...

Date Time

Unix Timestamp Date Format Handling dateString = "UNIX_TIMESTAMP_DATE_FORMAT" datetime.datetime.fromtimestamp(int(str(dateString)[:10])).strftime('%Y-%m-%d') The  datetime  module is used for manipulating dates and times. If we want to use DateTime we need to first import in our file. Example: import datetime dt = datetime.datetime.now() print(dt) Output:  2024-03-27 21:41:12.717541 # get the current date currDt = datetime.date.today() print( currDt ) Output: 2024-03-27 # get the current year currDt = datetime.date.today() print( currDt.year ) Output: 2024 # get the current month print( currDt.month ) Output: 3 # get the current date only print( currDt.day ) Output: 27 # get the current day print( currDt .strftime("%A")) Output:  Wednesday