User 12692182
User 12692182

Reputation: 981

Copying a tuple into multiple groups

For one of my programs, I want the user to input a color, and then the color gets split up between six faces. I have code like this: colors = color, color, color, color, color, color. As I'm only working with cubes, this is fine, but if want to create more intensive polygons, with hundreds of sides, this will get quite tedious. My question is, is the a more efficient way to do this?

color will always be a tuple

I'm aware that you can use the * to multiply tuples, but that just makes one long one, not multiple short ones, which is what I'm looking for

Upvotes: 2

Views: 49

Answers (1)

I hop that what you want...

x = 3  # can be change
color = (1, 2)
colors = [color for i in range(x)]  # colors == [(1, 2),(1, 2),(1, 2)]

# if it must be tuple
colors = tuple((color for i in range(x)))  # faster than convert list to tuple
#  colors == ((1, 2),(1, 2),(1, 2))

Upvotes: 3

Related Questions