Python Forum
Create array of values from 2 variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create array of values from 2 variables
#1
I have 2 variables that have values like :
var1=cel01 var2=disktypeHD
var1=cel02 var2=disktypeEF
var1=cel03 var2=disktypeEF
var1=cel04 var2=disktypeHD
These variables come from 2 FOR loops. like :

for cellname_from_phy in myrootphy.findall('cell'):
        v_cellname =cellname_from_phy.find('name').text
        #v_cellname1 = str(list(v_cellname.values())[0])
        print(v_cellname)
    myrootcelldetail = ET.parse(filename_celldetail)
    myrootcelldetail = myrootcelldetail.getroot()
    for model_celldetail in myrootcelldetail.findall('cell'):
        v_model =model_celldetail.find('makeModel').text
I mean, var1 is for each cel object I want to identify disktype where possible values are 2 only (HD or EF).
How can I create this in python ? Using list? array?
Reply
#2
Will each cell have only 1 disk type? You could use a dictionary
cells = {}
for ...
    cells[v_cellname] = v_model
Or if a cell can have multiple values.
cells = {}
for ...
    cells[v_cellname] = [model.find('makeModel').text for model in myrootcelldetail.findall('cell')]
Be warned that I don't understand your code at all including what part of the code is "var1" and what part is "var2". My guess is var1 is v_cellname and var2 is v_model.
paulo79 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create X Number of Variables and Assign Data RockBlok 8 968 Nov-14-2023, 08:46 AM
Last Post: perfringo
Question How create programmatically variables ? SpongeB0B 6 1,326 Aug-19-2023, 05:10 AM
Last Post: SpongeB0B
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,500 Jul-27-2022, 08:50 PM
Last Post: rob101
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,130 Apr-19-2022, 07:36 AM
Last Post: JulianZ
  How to create 2 dimensional variables in Python? plumberpy 5 1,865 Mar-31-2022, 03:15 AM
Last Post: plumberpy
  Calculate next rows based on previous values of array divon 0 1,790 Nov-23-2021, 04:44 AM
Last Post: divon
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,508 Mar-09-2021, 12:24 PM
Last Post: KMV
  variables vcnt, ocnt, and mcnt adding previous values and not resetting to 0 archanut 2 1,952 Feb-12-2021, 06:56 PM
Last Post: deanhystad
  Giving all possible values to four different variables quest_ 7 2,990 Jan-18-2021, 05:18 AM
Last Post: deanhystad
  cannot create animation on 2D array using Matplotlib and FuncAnimation Caffeine_Addict 1 2,503 Jan-12-2021, 11:35 AM
Last Post: Caffeine_Addict

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020