Linked Questions

698 votes
40 answers
259k views

How to iterate over a list in chunks

I have a Python script which takes as input a list of integers, which I need to work with four integers at a time. Unfortunately, I don't have control of the input, or I'd have it passed in as a list ...
Ben Blank's user avatar
  • 55.8k
2 votes
4 answers
400 views

Pythonic way to split a line into groups of four words? [duplicate]

Suppose I have string that look like the following, of varying length, but with the number of "words" always equal to multiple of 4. 9c 75 5a 62 32 3b 3a fe 40 14 46 1c 6e d5 24 de c6 11 17 cc 3d d7 ...
merlin2011's user avatar
  • 73.4k
-1 votes
1 answer
59 views

Create group of three lines with Python [duplicate]

I have a text file with many lines like this: aDB8786793440 bDB8978963432 cDB9898908345 dDB8908908454 eDB9083459089 fDB9082390843 gDB9083490345 I need to create groups of three, final format is less ...
Zoran's user avatar
  • 1
55 votes
6 answers
77k views

How to split a string using an empty separator in Python

What is a good way to do some_string.split('') in python? This syntax gives an error: a = '1111' a.split('') ValueError: empty separator I would like to obtain: ['1', '1', '1', '1']
Saullo G. P. Castro's user avatar
38 votes
8 answers
137k views

Load chrome extension using selenium

While running selenium, I need to load a chrome extension from the web store. In my research, I only found how to load an extension from the local machine. Is it possible for selenium to load an ...
D Deshmane's user avatar
  • 1,175
21 votes
5 answers
21k views

How to find subimage using the PIL library?

I want to find the sub-image from large image using PIL library. I also want to know the coordinates where it is found ?
Sagar's user avatar
  • 2,345
12 votes
4 answers
53k views

How to Split Python list every Nth element

What I am trying to do is pretty simple, but I couldn't find how to do it. Starting with 1st element, put every 4th element into a new list. Repeat with the 2nd, 3rd, and 4th elements. From: list = ...
octosquidopus's user avatar
16 votes
3 answers
13k views

Way to iterate two items at a time in a list?

I am wondering if there is a better way to iterate two items at a time in a list. I work with Maya a lot, and one of its commands (listConnections) returns a list of alternating values. The list will ...
Mathieson's user avatar
  • 1,244
9 votes
6 answers
9k views

Multithreading inside Multiprocessing in Python

I am using concurrent.futures module to do multiprocessing and multithreading. I am running it on a 8 core machine with 16GB RAM, intel i7 8th Gen processor. I tried this on Python 3.7.2 and even on ...
learner's user avatar
  • 909
4 votes
9 answers
388 views

how convert list of int to list of tuples

I want to convert a list like this l1 = [1,2,3,4,5,6,7,8] to l2 = [(1,2),(3,4),(5,6),(7,8)] because want to loop for x,y in l2: draw_thing(x,y)
lgwest's user avatar
  • 1,357
2 votes
7 answers
1k views

Python unexpected indentaton error main()

I have no idea how to fix this. I've tried retyping the program. I get an unexpected indentation error for the last main function. resident = 81 nonresident = 162 def main(): # initialize ...
David German's user avatar
3 votes
6 answers
1k views

Adding up number in a list with every 3 number

I have a list of numbers go in one row like this: 0 1 0 2 0 4 and it has about thousands of rows I want to add them up every 3 rows so the results will be like this: 1 6 I have already made the ...
ivanhoifung's user avatar
4 votes
1 answer
2k views

How to add or remove Chrome Extensions "after" selenium web-driver has been instantiated / defined

The title says it all - I am looking for a way (or ways) to load, enable, add (and likewise: disable / remove) extensions after the webdriver has been created. Context: Python, selenium (per tags). ...
JB-007's user avatar
  • 2,293
0 votes
1 answer
2k views

Finding and Connecting Multiple Canvas Items in Python

Background: I have a code which generates the cartesian coordinates of a network of regular shapes (in this case triangles), and then plots the vertices of the shapes on a Tkinter Canvas as small ...
MarkyD43's user avatar
  • 467
-1 votes
4 answers
414 views

Clean way to iterate through a list in pairs in Python?

I am using a string.split(':') function so that my list consists of firstname:lastname pairs (e.g. ["John", "Doe", "Alex", "Jacobson" ...] I know how to use a basic for loop where I would increment ...
AlwaysQuestioning's user avatar

15 30 50 per page