Re: Combining every pair of list items and creating a new list.

2017-07-19 Thread Rick Johnson
On Tuesday, July 18, 2017 at 5:19:56 AM UTC-5, Rahul K P wrote: > You can use a simple logic and list comprehension. > > so it will be like this > > lst = [1, 2, 3, 4, 5, 6, 7, 8] > print [lst[i:i+2] for i in range(0,len(lst),2)] No no no. Anybody can write code like that! To wow a professor

Re: Combining every pair of list items and creating a new list.

2017-07-18 Thread ast
a écrit dans le message de news:621ca9d5-79b1-44c9-b534-3ad1b0cf4...@googlegroups.com... Hi, I'm having difficulty thinking about how to do this as a Python beginner. But I have a list that is represented as: [1,2,3,4,5,6,7,8] and I would like the following

Re: Combining every pair of list items and creating a new list.

2017-07-18 Thread Rahul K P
You can use a simple logic and list comprehension. so it will be like this lst = [1, 2, 3, 4, 5, 6, 7, 8] print [lst[i:i+2] for i in range(0,len(lst),2)] Here 2 is the pairing number, You can set is as your need. On Tue, Jul 18, 2017 at 1:40 AM, wrote: > Hi, > >

Re: Combining every pair of list items and creating a new list.

2017-07-17 Thread Rick Johnson
On Monday, July 17, 2017 at 3:10:51 PM UTC-5, aaron.m@gmail.com wrote: > Hi, > > I'm having difficulty thinking about how to do this as a Python beginner. > > But I have a list that is represented as: > > [1,2,3,4,5,6,7,8] > > and I would like the following results: > > [1,2] [3,4] [5,6]

Re: Combining every pair of list items and creating a new list.

2017-07-17 Thread MRAB
On 2017-07-17 21:10, aaron.m.weisb...@gmail.com wrote: Hi, I'm having difficulty thinking about how to do this as a Python beginner. But I have a list that is represented as: [1,2,3,4,5,6,7,8] and I would like the following results: [1,2] [3,4] [5,6] [7,8] Any ideas? Thanks Those are

Combining every pair of list items and creating a new list.

2017-07-17 Thread aaron . m . weisberg
Hi, I'm having difficulty thinking about how to do this as a Python beginner. But I have a list that is represented as: [1,2,3,4,5,6,7,8] and I would like the following results: [1,2] [3,4] [5,6] [7,8] Any ideas? Thanks -- https://mail.python.org/mailman/listinfo/python-list