Python Forum

Full Version: Create array of values from 2 variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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.