Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For loop to make it easier
#3
A for loop using itertools and a itertools recipe
from itertools import tee


def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


columns = 'a', 'b', 'c', 'd', 'e', 'f', 'j', 'h'

for pair in pairwise(columns):
    print(pair)
Output:
('a', 'b') ('b', 'c') ('c', 'd') ('d', 'e') ('e', 'f') ('f', 'j') ('j', 'h')
Reply


Messages In This Thread
For loop to make it easier - by Amirdst - Feb-18-2020, 02:24 AM
RE: For loop to make it easier - by pyzyx3qwerty - Apr-28-2020, 10:18 AM
RE: For loop to make it easier - by Yoriz - Apr-28-2020, 04:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make for loop display on 1 Line Extra 3 1,439 Jan-12-2022, 09:29 PM
Last Post: Extra
  Looking for discord bot to make loop ping for address ip tinkode 0 1,835 Jul-26-2021, 03:51 PM
Last Post: tinkode
  Easier way to manage dependencies? Tylersuard 2 2,363 Jan-01-2020, 09:19 PM
Last Post: Tylersuard
  making the code easier, list comprehension go127a 2 2,078 May-26-2019, 06:19 PM
Last Post: Gribouillis
  How to make loop go back to the beginning if test evaluaes to True. FWendeburg 1 2,842 Feb-13-2019, 01:26 AM
Last Post: stullis
  How can I do it easier ? Mike Ru 7 4,976 Jul-31-2017, 05:41 PM
Last Post: wavic
  [ tools atom v pycharm ] -- when it comes to easier learning, and making life easier, oneofakindpython 2 3,378 Jun-18-2017, 08:19 AM
Last Post: 3cxmostar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020