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 7823841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:23:33+00:00 2026-06-02T08:23:33+00:00

# 2×3 dimensional list multidim_list = [ [1,2,3], [4,5,6], ] # 2x3x2 dimensional list

  • 0
# 2x3 dimensional list
multidim_list = [ 
                  [1,2,3],
                  [4,5,6],    
                ]
# 2x3x2 dimensional list
multidim_list2 = [ 
                   [ 
                     [1,2,3],
                     [4,5,6],  
                   ],
                   [ 
                     [7,8,9],
                     [10,11,12],  
                   ]
                 ]

def multiply_list(list):
    ...

I would like to implement a function, that would multiply all elements in list by two. However my problem is that lists can have different amount of dimensions.

Is there a general way to loop/iterate multidimensional list and for example multiply each value by two?

EDIT1:
Thanks for the fast answers.
For this case, I don’t want to use numpy.
The recursion seems good, and it doesn’t even need to make copy of the list, which could be quite large actually.

  • 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-02T08:23:35+00:00Added an answer on June 2, 2026 at 8:23 am

    Recursion is your friend:

    from collections import MutableSequence
    def multiply(list_):
        for index, item in enumerate(list_):
            if isinstance(item, MutableSequence):
                multiply(item)
            else:
                list_[index] *= 2
    

    You could just do isinstance(item, list) instead of isinstance(item, MutableSequence), but the latter way is more futureproof and generic. See the glossary for a short explanation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have dict like: mydict= {'a':[],'b':[],'c':[],'d':[]} list like: log = [['a',917],['b', 312],['c',303],['d',212],['a',215],['b',212].['c',213],['d',202]] How do i
For example, http://api.hostip.info/get_html.php?ip=12.215.42.19 When visiting that URL, it will return: Country: UNITED STATES (US)
I am getting an error message like so: Linear.hs:215:27: Couldn't match expected type `forall
When I view the following in Chrome 13.0.782.215 Linux, I find that the div
Hello I create yii app in temp IP address like this http://74.220.215.220/~cineklik/ but links
I have this issue when I would like to go the Game Over screen.
The R 2.15 release notes and the documentation of makePSOCKCluster state that communication can
if($player[$x]->name == $p->name || $player[$x]->name == $target) unset $player[$x]; //<-- line 215 commenting out
I am working to solve a problem that is a bit similar to Euler
I'm embedding youtube clips on my site with the following code: <object width=259 height=215

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.