[PYTHON] I tried a little bit of the behavior of the zip function

Yes. Some of the comments I received used zip, but I didn't know how to use it or how it behaves, so check it roughly.

op.py


#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import sys
import io
import re
import math

####Memory usage and operating time check preparation
from guppy import hpy
import time
start = time.clock()
h = hpy()
####Up to here
i1=[1,2,3,4,5]
i2=[1,2,3,4,5]
z = zip(i1,i2)
print z
print type(z)
print z[0]

i1=[1,2,3,4,5]
i2=[3,4,5]
z = zip(i1,i2)
print z

s1=['dog','cat','bird','kame']
s2=['dog','cat','bird','kame']
z = zip(s1,s2)
print z
s1=['dog','cat','bird','kame']
s2=['dog','kame']
z = zip(s1,s2)
print z
#print m

####Memory usage and operating time output
end = time.clock()
print (h.heap())
print (end - start)

result [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)] <type 'list'> (1, 1) <type 'tuple'> [(1, 3), (2, 4), (3, 5)] [('dog', 'dog'), ('cat', 'cat'), ('bird', 'bird'), ('kame', 'kame')] [('dog', 'dog'), ('cat', 'kame')]

Hmmm, I wonder if (x, y) or something like a dictionary is put in a list and returned. Is it the remainder of the one with the smaller number of elements and the one with the larger number? Seems to be ignored. I can't think of a way to use it at all, so I can't really understand how to use it unless I imitate what other people are writing and check the behavior.

Recommended Posts

I tried a little bit of the behavior of the zip function
I tried the pivot table function of pandas
I just changed the sample source of Python a little.
I made a function to check the model of DCGAN
I tried to fight the Local Minimum of Goldstein-Price Function
I tried to get the index of the list using the enumerate function
I tried the asynchronous server of Django 3.0
I tried 3D detection of a car
I tried to display the altitude value of DTM in a graph
I tried to verify the result of A / B test by chi-square test
Python: I want to measure the processing time of a function neatly
I tried to predict the behavior of the new coronavirus with the SEIR model.
I made a function to see the movement of a two-dimensional array (Python)
[Python] I tried substituting the function name for the function name
I tried cluster analysis of the weather map
Get the caller of a function in Python
I tried to touch the API of ebay
I tried using the image filter of OpenCV
I did a little research on the class
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
[Python] I tried to get the type name as a string from the type function
I tried to create a model with the sample of Amazon SageMaker Autopilot
I tried to understand the learning function of neural networks carefully without using a machine learning library (first half).
I tried to learn the sin function with chainer
Draw a graph in Julia ... I tried a little analysis
I tried to summarize the basic form of GPLVM
I tried the MNIST tutorial for beginners of tensorflow.
# Function that returns the character code of a string
I tried to approximate the sin function using chainer
I examined the argument class_weight of Chainer's softmax_cross_entropy function.
I tried using the API of the salmon data project
I tried to visualize the spacha information of VTuber
I tried to erase the negative part of Meros
I tried scraping the advertisement of the pirated cartoon site
Zip 4 Gbyte problem is a story of the past
I tried using Python (3) instead of a scientific calculator
I tried the simplest method of multi-label document classification
A little bit from Python using the Jenkins API
I tried to classify the voices of voice actors
I tried running the sample code of the Ansible module
I tried to summarize the string operations of Python
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
I tried to find the entropy of the image with python
A super introduction to Django by Python beginners! Part 6 I tried to implement the login function
[Horse Racing] I tried to quantify the strength of racehorses
I tried "gamma correction" of the image with Python + OpenCV
A note on the default behavior of collate_fn in PyTorch
I tried to get the location information of Odakyu Bus
I tried the accuracy of three Stirling's approximations in python
Reuse the behavior of the @property method by using a descriptor [16/100]
I tried the super-resolution algorithm "PULSE" in a Windows environment
I tried to find the average of the sequence with TensorFlow
I thought a little because the Trace Plot of the stan parameter is hard to see.
I tried refactoring the CNN model of TensorFlow using TF-Slim
I tried to compare the accuracy of machine learning models using kaggle as a theme.
I tried face recognition of the laughter problem using Keras.
I tried replacing the Windows 10 HDD with a smaller SSD
I made a dot picture of the image of Irasutoya. (part1)
I tried the changefinder library!