Use a list or array in Python?
<p>I need to store information for 6 items and their respective length, width and cost values and then work out some values based on user input.</p>

<p>With the help of jcusick, I have now the code below. </p>

<p>I now need help for the items marked in the comments (#).</p>

<p>You do not need to write the complete code - pointing in right direction is perfect. </p>

<p>So far I have:</p>

<pre><code>cost = {}
cost['Themon'] = 450
cost['Larrec'] = 700
cost['Medrec'] = 500
cost['Parallel'] = 825
cost['Suncatch'] = 400
cost['Chantran'] = 975

length = {}
length['Themon'] = 3.2
length['Larrec'] = 3.4
length['Medrec'] = 2.1
length['Parallel'] = 5
length['Suncatch'] = 3
length['Chantran'] = 9

width = {}
width['Themon'] = 2.3
width['Larrec'] = 3
width['Medrec'] = 2
width['Parallel'] = 4
width['Suncatch'] = 3
width['Chantran'] = 6

area = {}
area['Themon'] = 1 # how do i calculate the area (l*w) by referencing the lenght and width dictionary 
area['Larrec'] = 1
area['Medrec'] = 1
area['Parallel'] = 1
area['Suncatch'] = 1
area['Chantran'] = 1

#menu
ans=True
while ans:
    print("""
    Enter 1. to find cheapest garden deck 
    Enter 2. to display the names of garden decks over a certain lenght
    Enter 3. to display the number of garden decks that are available over a certain area
    Enter 4. to quit
    """)
    ans=input("What option would you like? ")
    if ans=="1":
        print (min(cost, key=cost.get))
    elif ans=="2":
        input_length = input("\n Please enter minimum deck length between 2 and 15 metres")
        print # i need to display names of the decks greater than the user input length
    elif ans=="3":
        input_area = input("\n Please enter deck area in metres squared between 4 and 80")
        print # i need to display the number of garden decks that are greater that the user input area
    elif ans=="4":
        print("\n Thank you for using Penny's Decking")
    else:
        print("\n Not a valid choice")
</code></pre>

<p>I think pandas might be overkill for a small piece of code like this. For your particular example, arrays would be a faster storage method. I would go so far as to say, though, that a list is probably the more pythonic way to handle this particular scale. Your performance won't be terribly affected either way here, and it's slightly more readable now, rather than using an array. </p>

<p>For further reading, sometimes a namedtuple can be helpful in larger scale examples in which you keep, and access, records:
<a href="https://docs.python.org/3/library/collections.html#collections.namedtuple" rel="nofollow">https://docs.python.org/3/library/collections.html#collections.namedtuple</a></p>

python python-3.x