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

  • Home
  • SEARCH
  • 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 7169995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:07:22+00:00 2026-05-28T15:07:22+00:00

python newbie here. I’m writing the code to control an experiment that has multiple

  • 0

python newbie here. I’m writing the code to control an experiment that has multiple variables. The variables are defined in a csv file something like:

Temp, Voltage, Pressure
23, 4.8, 19
23;28, 4.8, 19;23

I read the file and create a dictionary, that part works ok. for example the first line will be:

{'Temp': ['23'], 'Voltage': ['4.8'], 'Pressure': ['19']}

and that will control a single experiment.
The second line will be:

{'Temp': ['30', '28'], 'Voltage': ['4.8'], 'Pressure': ['19', '23']}

What I would like is a way to generate all the possible dictionaries, in sequence, from that line. For example the second line will be expanded to four experiments:

{'Temp': ['30'], 'Voltage': ['4.8'], 'Pressure': ['19']}
{'Temp': ['30'], 'Voltage': ['4.8'], 'Pressure': ['23']}
{'Temp': ['28'], 'Voltage': ['4.8'], 'Pressure': ['19']}
{'Temp': ['28'], 'Voltage': ['4.8'], 'Pressure': ['23']}

The order is important (the last column is the inner loop). I have a list with the keys in the order I want to iterate. For example:

('Temp', 'Voltage', 'Pressure')

in this case.

This is an oversimplification and there is a big number of variables (columns) in the system.

I’m thinking about a parallel dictionary with counters to keep track of the possible cases and current case for each variable, but maybe I’m missing a more elegant way to express this in python.

Regards,

–ga

  • 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-05-28T15:07:23+00:00Added an answer on May 28, 2026 at 3:07 pm

    Yup, you want itertools.product(). You just need to extract the lists from the dict & re-wrap the results with your dictionary structure.

    from itertools import product
    def _combinations_for_record(d):
        for tmp, vlt, prs in product(d['Temp'], d['Voltage'], d['Pressure']):
            yield {"Temp": [tmp], "Voltage": [vlt], "Pressure": [prs]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python newbie here. I'm writing a script that can dump some output to either
Python newbie here. I was trying to troubleshoot an issue with writing a csv
I'm a newbie to python and the app engine. I have this code that
I'm a Python newbie, so I'm sure this is easy. Here's the code in
Python newbie here: I'm writing a market simulation in Python using Pysage, and want
Python and django newbie question, here is code: class Client(User) #some fields client=Client() client.save()
As a newbie to Python, and mainly having a background of writing scripts for
I'm newbie in Python. I can't understand why this code does not work: reOptions
I'm a newbie with a little experience writing in BASIC, Python and, of all
I'm a Python(3.1.2)/emacs(23.2) newbie teaching myself tkinter using the pythonware tutorial found here .

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.