Python Forum
How does this generator work?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does this generator work?
#1
code = "F9E56d"

rgb = tuple(int(code[i:i+2], 16) for i in (0, 2, 4))
Hi, I don't quite understand the logic of this code.
Can you write me this code in a normal for loop so I can understand that?
Reply
#2
code = "F9E56d"

rgb = tuple(int(code[i : i + 2], 16) for i in (0, 2, 4))

print(rgb)

rgb = []
for i in (0, 2, 4):
    rgb.append(int(code[i : i + 2], 16))

rgb = tuple(rgb)

print(rgb)
Output:
(249, 229, 109) (249, 229, 109)
JgKSuperstar likes this post
Reply
#3
Thank you so much for your valuable response.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  receive from a generator, send to a generator Skaperen 9 5,509 Feb-05-2018, 06:26 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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