Python Forum
convert this List Comprehensions to loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert this List Comprehensions to loop
#1
Does anyone know how to convert this List Comprehensions to normal for loop code:
results = ['A' , 'B', 'C' , 'D']
]for i in [results[c:c+2] for c in range(0,len(results)) if c%2 == 0]:
    print(*i)
output:
A B
C D
Reply


Messages In This Thread
convert this List Comprehensions to loop - by jacklee26 - Oct-20-2022, 02:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  convert string to float in list jacklee26 6 1,967 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  convert a list to links Pir8Radio 3 1,141 Nov-28-2022, 01:52 PM
Last Post: Pir8Radio
  Are list/dict comprehensions interpreted really sequentially? anata2047 3 1,482 May-31-2022, 08:43 PM
Last Post: Gribouillis
  Convert list to interger Clives 5 1,648 May-09-2022, 12:53 PM
Last Post: deanhystad
  Convert each element of a list to a string for processing tester_V 6 5,417 Jun-16-2021, 02:11 AM
Last Post: tester_V
  convert numbers into list lokesh 1 2,411 Jun-03-2021, 06:37 AM
Last Post: menator01
Question convert unlabeled list of tuples to json (string) masterAndreas 4 7,520 Apr-27-2021, 10:35 AM
Last Post: masterAndreas
Star Convert Bytearray into List using list() Shlok 2 4,230 Feb-18-2021, 10:44 AM
Last Post: deanhystad
  convert List with dictionaries to a single dictionary iamaghost 3 2,892 Jan-22-2021, 03:56 PM
Last Post: iamaghost
  Convert string to JSON using a for loop PG_Breizh 3 3,011 Jan-08-2021, 06:10 PM
Last Post: PG_Breizh

Forum Jump:

User Panel Messages

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