

Photo by Editor | Chat GPT
. Introduction
Working with Azigar means to rely on many of its built -in functions, especially for data science tasks. Popular functions such as len
For, for, for,. max
For, for, for,. range
Etc., data scientists are common in the tool cut and useful in different situations. However, many built -in these functions are not recognized because they are considered useless.
In this article, we will look for seven different built -in ines that you think this is a joke but in reality their requests are very useful. These built -in are different from your usual code, but once you realize their usefulness, they will find their place in your workflow.
Careful Let’s enter it.
. 1 divmod
Built -in Function
Many people rarely use divmod
Built -in function, or even know it is. divmod
Built -in function returns number two: Floor Division and the result of modules operation. It may be useless because we can use syntax like a // b
And a % b
Bullets, especially when we rarely need both results at the same time.
In cases of real -world use, we often need both results and want to faster this process once permanently. Something divmod
Applications – including time changes, pages, batching, and cleaner hash mathematics – shows its utility.
Let’s see the example of use:
total_seconds = 7132
minutes, seconds = divmod(total_seconds, 60)
hours, minutes = divmod(minutes, 60)
print(f"Time: {hours:02d}:{minutes:02d}:{seconds:02d}")
Where the output is shown below:
With a function, we can split the number equally, which is useful in many applications.
. 2 slice
Built -in Function
slice
The built -in function is used to separate or extract some parts of the series like strings, lists, or tuples. It may be useless because we can easily form a slice object obj(1:10:2)
.
However, the power of slice
The built -in function appears when you need to reuse the same slicing principle in different items. The function helps us maintain a permanent analysis logic and allow us to develop strategies for data processing.
An example of implementation is:
evens = slice(0, None, 2)
text = "abcdefghij"
print(text(evens))
Output is shown below:
slice
The above built -in shows that we can re -use the rules to take every other role.
. 3 iter
Built -in Function
iter
The built -in function produces an Atroter Object that processes the items one by one. It may be unnecessary because we already have ” ‘while the truth and the “brake` sample. ” Still, it is helpful because it allows a better structure in the cleaner code and data pipeline.
For example, we can use iter
To control staming data processing:
import io
f = io.BytesIO(b"12345678")
for block in iter(lambda: f.read(3), b""):
print(block)
Where the output is shown below:
. 4 memoryview
Built -in Function
memoryview
Built -in function creates a memory view from internal data without copying the Object. It looks like an unnecessary task that has no place in the standard weird workflow.
However, memoryview
The function is useful when handling large binary data as it facilitates users to access and edit it without making a new item. For example, you can convert a section of the data into the same memory without copying, as shown in the following code.
buf = bytearray(b"hello")
mv = memoryview(buf)
mv(0) = ord('H')
print(buf)
mv(:) = b"HELLO"
print(buf)
Output is shown below:
bytearray(b'Hello')
bytearray(b'HELLO')
The assignment is made in the same memory, which is helpful for any sensitive task.
. 5 any
Built -in Function
any
The built -in function returns to Bowen Value by checking the items in a capable object. It lifts True
If any element in imitation is true and False
Otherwise. The function seems useless, as it seems that it changes a simple checking loop.
However, the power of any
The function is in the ability to make temporary items and avoid using a slow diagnosis with generators, which means that the function can have a clear loop logic and reduce the use of memory.
An instance of azigar code is shown below:
files = ("report.txt", "sales.csv", "notes.md")
print(any(f.endswith(".csv") for f in files))
Where the output is shown below:
It is beneficial when we have matters that require verification or protective terms.
. 6 all
Built -in Function
all
Built -in Function also resembles any
But the difference is that the former just comes back True
Unless all
The items in the repetition are true. Likewise any
, all
The built -in function is often considered useless because the manual loop can achieve the same result.
It is a valuable built -in because it provides a declaration and short circuit verification that every element is true with a slow diagnosis for generators. This means that the code is clean and takes less memory.
For example is using the following code:
required = ("id", "name", "email")
record = {"id": 1, "name": "Ana", "email": "a@x.io"}
print(all(k in record for k in required))
Where the output is shown below:
Applications include scheme check and input verification.
. 7 zip
Built -in Function
zip
The built -in function is used to collect multiple atable items in taps. It may be unnecessary, why a developer can only repeat with the index, such as with a for i in range(len(x)):
The loop, or because it only returns the tiples.
zip
The built -in function, however, is far more helpful because it allows you to loop multiple epilepsy items without indicators. Since the function only produces a couple when necessary, it will not waste memory. When we manually manage indexing, it also avoids any ordinary index errors.
The example of Azgar is shown below:
keys = ("id", "name", "email")
vals = (1, "Ana", "a@x.io")
record = dict(zip(keys, vals))
print(record)
Where the output is shown below:
{'id': 1, 'name': 'Ana', 'email': 'a@x.io'}
There are a lot of applications, such as indexes without mathematics or parallel to counted counters.
. Conclusion
Python is a useful programming language for any data -related activity, and its built -in functions are an important part of this utility. However, some built-in are considered useless-that is, unless you really use them and do not realize how valuable they are.
I hope it has helped!
Cornelius Yodha Vijaya Data Science is Assistant Manager and Data Writer. Elijan, working in Indonesia for a full time, likes to share indicators of data and data through social media and written media. CorneLius writes on various types of AI and machine learning titles.