![]() If we want to bind or zip the data of different arrays, then we can go for the zip function in Python of NumPy. In this example, we will map the student data for name, roll number, city, and grade they obtained and print the result.Īrr3 = #calling zip function here to bind two array elements This is for beginners to show the working.Īrr1 = In this example, we are creating two iterable objects and just calling the zip function on them. The same length is not mandatory.įollowing are the examples are given below: Example #1 zip() function does not bond to the length of the iterable object.This operation can be performed by using the unzip() function. Like we zip our object into a single object, we can also perform unzip of the object. ![]() Pints to be remembered while working with the zip() function in Python ![]() So, in the end, it will generate the object which will be going to contain the mapped object of the student object. Result = zip(studentName, rollNumber, city, address) So in the output, we will have all the student data mapped with the corresponding record of the student. After that, we can pass this input parameter in the zip() function. We need to create three arrays that will contain the name, roll number, marks, city, and address of the student, respectively. Suppose we have a student to whom we must bind the data according to roll number, marks, city, and address. Now we will talk about the real-time scenario in which we cause it. We are holding the data into the result variable here, which will be a zipped iterable object containing the result. In the last line, we are calling the zip() function and passing both the array into it as a parameter. But in Python, we have a zip() function which will bind the variable of two or more different arrays into one single array. If we talk about any other programming language, then we need an object which will bind both the variable of the student class or else we need to create a map that will map the value of the student as key-value pair. The first array contains the name of the student and the second array contains the roll number associated with the student. In the above example, we are creating two arrays. Let’s see one example to understand its working in a better way arr1 = Īrr2 =
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |