Built-in Python function that makes an iterator that aggregates elements from each of the iterables.
Questions tagged [python-zip]
58 questions
1
vote
1 answer
Why aren't two `zip` objects equal if the underlying data is equal?
Suppose we create two zips from lists and tuples, and compare them, like so:
>>> x1=[1,2,3]
>>> y1=[4,5,6]
>>> x2=(1,2,3)
>>> y2=(4,5,6)
>>> w1=zip(x1,y1)
>>> w2=zip(x2,y2)
>>> w1 == w2
False
But using list on each zip shows the same result:
>>>…

newview
- 648
- 6
1
vote
1 answer
How to zip 2D arrays
a=np.array([[1,2,3],[4,5,6],[7,8,9]])
b=np.array([[1,2,3],[4,5,6],[7,8,9]])
I've 2 identical 2D arrays, I'm trying to zip them element-wise. It should look like:
[[(1,1) (2,2), (3,3)]
[(4,4) (5,5) (6,6)]
[(7,7) (8,8) (9,9)]]
I've tried the…

Pixel_Bear
- 97
- 1
- 1
- 11
1
vote
2 answers
the ways of using zip function to generate the cell location based on the row and column information
I created the following dataframe, and would like to identify the cells which are Null,
import pandas as pd
import numpy as np
data = [{'a': 1, 'b': 2, 'c':3},
{'a':10, 'b': np.NaN, 'c':"" },
{'a':10, 'b':"" , 'c':np.NaN }]
df =…

user785099
- 5,323
- 10
- 44
- 62
1
vote
1 answer
How to convert a JSON file to a graph with library networkx in Python?
I have a big JSON file and I want to convert it with networkx library to a graph.
The JSON file contains so many nodes like:
{"data": [{
"d": 2,
"source": "C",
"target": "L"
},...]}
I already opened the JSON file and I extracted each "data"…

Sara
- 419
- 1
- 6
- 14
1
vote
3 answers
Zip lists by function output in Python
It is known that if we have two lists in python l1 and l2, one can use zip(l1, l2) in order to create a list of tuples from both l1 and l2.
Now, lets assume that we have two functions f1 and f2. I would like to create a list of tuples with elements…

Sagi Shadur
- 226
- 1
- 4
- 14
1
vote
0 answers
Multiprocessing on large pandas dataframe is suddenly slow
I am attempting to use multiprocessing.Pool.starmap to add a new column to my pandas data frame, based on the value of a few other columns, with the following code:
def my_func(a, b, c, d, e, f):
if pd.isna(b) or b == 0 or a == b:
return…

QuestionAskingPerson
- 11
- 2
1
vote
1 answer
How to bypass the alert window while downloading a zipfile?
If I open the link: https://dibbs2.bsm.dla.mil/Downloads/RFQ/Archive/ca210731.zip
This link shows the window and I need to press the OK button and it downloads the file.
The alert is not from the browser, it is from the page itself.
But When I tried…

Atom Store
- 961
- 1
- 11
- 35
1
vote
1 answer
'int' object is not iterable while using zip in python
a = [1, 2, 4, 5, 7, 8, 10]
n = len(a)
d = 3
c = []
for i in range(n):
for j in range(i,n):
for k in range(j,n):
for x,y,z in zip(a[i],a[j],a[k]):
print(x,y,z)
Error : Traceback (most recent call last):
File "", line 8, in…

Prime coder
- 91
- 1
- 10
1
vote
2 answers
How to cycle through a list and add one item to each tuple in a list of tuples using 'zip()'?
My data file contains eight thousand lines, where each line is a tuple. The first two lines are:
(2000, 1, 1, 1, 336)
(2000, 1, 1, 2, 335)
I would like to repeatedly cycle through the weekdays and append a weekday to each data tuple. The list of…

chrhalv
- 21
- 4
1
vote
1 answer
Python for loop get n rows from 2 datasets
I want to get n rows from x_train and y_train in for loop using zip() each time. So the code below is what i have tried to do.At each iteration i update prev batch and next batch so i will get [0-5],[5-10],... rows from both 2d numpy…

Marios Nikolaou
- 1,326
- 1
- 13
- 24
1
vote
1 answer
"can only concatenate str (not "int") to str" when zipping list of strings and list of objects
I get this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Hunter\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File…

1Ghasthunter1
- 91
- 8
0
votes
1 answer
TypeError: cannot determine truth value of Relational with dict(zip()), only with direct output
EDIT:
The problem only appears when trying to get "direct output" of the result of dict(zip(....
This code, with output via print, works fine
import sympy as sp
x, y = sp.symbols('x,y')
d = dict(zip([x, y], [1, 1]))
print(d)
but simply entering…

sancho.s ReinstateMonicaCellio
- 14,708
- 20
- 93
- 185
0
votes
2 answers
Why does same code outputs different values?
import itertools
def f(x,y,z,w):
return ((x and y) or (y and z)) == ((not(x) or w) and (not(w) or z))
for p in itertools.permutations("xyzw"):
ans = []
t = [(0,1,1,1), (0,1,0,0), (0,1,0,1)]
for r in t:
#ans.append(f(*r))
…
0
votes
1 answer
How to create a dictionary to count value (username) appearances in two files? - Python
trying to complete a task for my course;
I have two files that I need to read from and compare to get a count.
One file contains login information in the format of:
username, password
The other file has the tasks in the format of:
username, task…

Livvy Wilson
- 45
- 5
0
votes
3 answers
How do I use zip print on a list of strings in python without it returning with quotations surrounding them?
Current code:
reps = ['x 5', 'x 5', 'x 3', 'x 5', 'x 5', 'x 5+']
b = [90, 122, 135, 146, 168, 191]
print(str(list(zip(b,reps))).replace(',',''))
here is the current output:
[(90 'x 5') (112 'x 5') (135 'x 3') (146 'x 5') (168 'x 5') (191 'x…

Lowsaint 98
- 13
- 1