-2

In php I can have an array

$shop["rose"] = array(1 , 15);
$shop["jim"] = array( 5 , 7);
$shop["bud"] = array( 9 , 22);

If I type $shop["jim"] I get the array for Jim. How could I do this in Python?

Thanks Glenn

user3757731
  • 277
  • 2
  • 11

1 Answers1

0

You can use Lists and Dictionaries in Python in order to use the same strategy:

shop = {
    'rose': [1,15],
    'jim': [5,7],
    'bud': [9,22]
}

print(shop)         # {'rose': [1, 15], 'jim': [5, 7], 'bud': [9, 22]}
print(shop['rose']) # [1, 15]
Claudio Busatto
  • 721
  • 7
  • 17