0

I have a list as follows:

part_list = ['Particle-8-c', 'Particle-38-c', 'Particle-37-c', 'Particle-13-c', 'Particle-57-c', 'Particle-62-c', 'Particle-63-c', 'Particle-58-c']

I need to automate the assignment of variables to get an outcome as such:

IP1 = MI['Particle-38-c']
IP2 = MI['Particle-8-c']
IP3 = MI['Particle-37-c']
IP4 = MI['Particle-62-c']
IP5 = MI['Particle-63-c']
IP6 = MI['Particle-13-c']
IP7 = MI['Particle-58-c']
IP8 = MI['Particle-57-c']

The variable names should be 'IP' + index (e.g. IP1 for the first variable) and assigned to MI + a list of each item in the dictionary (e.g. MI['item1']). The number of items in the list may vary depending on usage.

I have unsuccessfully tried for index, item in enumerate(coh_list): and similar variations.

khelwood
  • 55,782
  • 14
  • 81
  • 108
Ch123
  • 11
  • 1
  • Whenever you find yourself trying to do this, it should set off red flags. Perhaps consider using a dictionary instead – Chris Oct 12 '22 at 16:50
  • 3
    No, you do not need / want this. Dictionary / List is the correct data structure. How are you planning on using these dynamically created variables anywhere? – luk2302 Oct 12 '22 at 16:51
  • @luk2302 the dynamically created variables are required for automation of a process in another software, abaqus to the precise. It has to be in that format. – Ch123 Oct 12 '22 at 16:57
  • No, it does not. How are you specifically trying to use those? How will you know if IP172 exists when using it?? How are you planning on using any of those variables? Don't say "I will be using it with this and that" - if you actually attempt using them you will see this does not work at all. – luk2302 Oct 12 '22 at 17:01

0 Answers0