Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:00:57+00:00 2026-06-06T06:00:57+00:00

I have a variable representing a bmp image with the following structure: image=[line1, line2,

  • 0

I have a variable representing a bmp image with the following structure:

image=[line1, line2, ... linen] 
line=[pix1,pix2,...,pixn]
pix=[r,g,b]

thus for instance the contents of this variable may look like

[[[0,0,0],[1,0,1],[2,4,5]],[[3,4,5],[1,7,4],[1,3,5]],[[2,4,2],[1,6,7],[1,9,0]]]

Now I would like to convert the pix-lists of each line-item into tuples, so the contents will become like this:

[[(0,0,0),(1,0,1),(2,4,5)],[(3,4,5),(1,7,4),(1,3,5)],[(2,4,2),(1,6,7),(1,9,0)]]

I could do this by

for i in range(0,len(image)-1):
   for j in range(0,len(image[0])-1):
      image[i][j] = tuple(image[i][j])

but this doesn’t seem to be the most “pythonesque” way to do it, and I need the fastest computational method possible, which the above seems to be far from.

I tried it with

[tuple(pix) for pix in line for line in image]

as I though this should be faster, but of course the above fails miserably.

So is there anybody who could help me convert my sublists of pix into tuples the fastest way possible? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:00:59+00:00Added an answer on June 6, 2026 at 6:00 am

    How about this:

    [map(tuple, line) for line in image]
    

    And to encompass comments for completeness. In Python 3.x, where map is a generator, you’d use:

    [list(map(tuple, line)) for line in image]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable of double type representing a value of about 34.323423423123456. I'd
Let's say that I have an adt representing some kind of tree structure: data
I have variable @count of datatype int.I am setting values to this @count. I
i have variable $lang which convert string to the selected language but i am
How I can have variable number of parameters in my function in C++. Analog
I have a variable foo that contains a time, lets say 4pm today, but
I have a variable in my xsl that may or may not be declared.
I have a variable that im define with another variable and some text. $title
I have a variable containing a string. The string can come in several ways:
I have three variable declared as doubles: double Delay1 = 0; double Delay2 =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.