I want to enumerate through an array called zones; within each zone I want to enumerate through another array zoneIDX{X} (X is the index of the zones array) When I make a new variable called snotelIDX and then try to enumerate through the array that the new variable is associated with it enumerates through the string instead of the array -
zones=["Zone 1 - Yellowstone NP","Zone 2 - Absaroka Mtns","Zone 7 - Owl Creek/Bridger Mtns","Zone 8 - Bighorn Mtns West"]
-
## Snotels in Zone 1 - Yellowstone NP
-
zoneIDX0=["CANYON","LEWIS LAKE DIVIDE","SNAKE RIVER STATION","SYLVAN LAKE","SYLVAN ROAD","THUMB DIVIDE","TWO OCEAN PLATEAU"]
-
## Snotels in Zone 2 - Absaroka Mtns
-
zoneIDX1=["BEARTOOTH LAKE","BLACKWATER","BURROUGHS CREEK","CASTLE CREEK","EVENING STAR","KIRWIN","MARQUETTE","PARKER PEAK","TIMBER CREEK","WOLVERINE","YOUNTS PEAK"]
-
## Snotels in Zone 7 - Owl Creek/Bridger Mtns
-
zoneIDX2=["OWL CREEK"]
-
## Snotels in Zone 8 - Bighorn Mtns West
-
zoneIDX3=["BALD MOUNTAIN","BONE SPRINGS DIVIDE","POWDER RIVER PASS","SHELL CREEK"]
-
-
for j, v in enumerate(zones):
-
IDX = j
-
snotelIDX = "zoneIDX" + str(IDX)
-
for k, w in enumerate(snotelIDX):
-
if I print snotelIDX it prints the right thing
zoneIDX0
zoneIDX1
zoneIDX2 and so on
but enumerates through s n o t e l I D X
thanks
4 1832 bvdet 2,851
Expert Mod 2GB
Python is doing exactly what you told it to do. You are assigning a string to the variable snote1IDX. A string is a sequence similar to a list. Are you trying to assign each element in zones to a variable identifier? If so, this can be accomplished using globals().update() or exec(). - for j, v in enumerate(zones):
-
globals().update({"snote1%s" % j: v})
-
for k, w in enumerate(v):
-
print "snote1%s" % j, w
-
-
# another way
-
for j, v in enumerate(zones):
-
exec "snote2%s=v" % (j)
-
Note that v is a reference to the sublist in zones so that any modification to v will also modify the sublist in zones.
Or did you mean to do this: - for j, v in enumerate(zones):
-
IDX = j
-
snotelIDX = "zoneIDX" + str(IDX)
-
for k, w in enumerate(v):
What I want is to enumerate through the zones and within each zone enumerate through the zoneIDX that goes with the zone out put like
Zone 1 - Yellowstone NP
CANYON
LEWIS LAKE DIVIDE
SNAKE RIVER STATION
SYLVAN LAKE
SYLVAN ROAD
THUMB DIVIDE
TWO OCEAN PLATEAU
Zone 2 - Absaroka Mtns
BEARTOOTH LAKE
BLACKWATER
BURROUGHS CREEK
CASTLE CREEK
EVENING STAR
KIRWIN
MARQUETTE
PARKER PEAK
TIMBER CREEK
WOLVERINE
YOUNTS PEAK
Zone 7 - Owl Creek/Bridger Mtns
OWL CREEK
Zone 8 - Bighorn Mtns West
BALD MOUNTAIN
BONE SPRINGS DIVIDE
POWDER RIVER PASS
SHELL CREEK
I tried the suggestions but it did not enumerate through them correctly
Thanks for your help
You would use two lists that correspond to each other. - zones=["Zone 1 - Yellowstone NP","Zone 2 - Absaroka Mtns","Zone 7 - Owl Creek/Bridger Mtns","Zone 8 - Bighorn Mtns West"]
-
## Snotels in Zone 1 - Yellowstone NP
-
zoneIDX0=["CANYON","LEWIS LAKE DIVIDE","SNAKE RIVER STATION","SYLVAN LAKE","SYLVAN ROAD","THUMB DIVIDE","TWO OCEAN PLATEAU"]
-
## Snotels in Zone 2 - Absaroka Mtns
-
zoneIDX1=["BEARTOOTH LAKE","BLACKWATER","BURROUGHS CREEK","CASTLE CREEK","EVENING STAR","KIRWIN","MARQUETTE","PARKER PEAK","TIMBER CREEK","WOLVERINE","YOUNTS PEAK"]
-
## Snotels in Zone 7 - Owl Creek/Bridger Mtns
-
zoneIDX2=["OWL CREEK"]
-
## Snotels in Zone 8 - Bighorn Mtns West
-
zoneIDX3=["BALD MOUNTAIN","BONE SPRINGS DIVIDE","POWDER RIVER PASS","SHELL CREEK"]
-
zone_desc = [zoneIDX0, zoneIDX1, zoneIDX2, zoneIDX3]
-
-
for ctr in range(len(zones)):
-
print zones[ctr]
-
for descr in zone_desc[ctr]:
-
print " ", descr
dwblas - Thank you so much; Your code suggestion worked perfectly; just what I wanted.
Thank you for taking the time to help me out!!!!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve G |
last post by:
Steve G Feb 1, 1:12 pm show options
From: "Steve G" <sgr...@computicle.com> - Find messages by this author
Date: Tue, 01 Feb 2005 13:12:42 -0800
Local: Tues, Feb 1 2005 1:12 pm
Subject:...
|
by: Alexander Muylaert |
last post by:
Hi
In delphi we can create an array of an enum.
type
TMyEnum = (meRed, meGreen, meBlue);
const
cMyArray : array of TColor = (clRed, clGreen, clBlue);
|
by: ALI-R |
last post by:
Is it a possibel to assign an array to a DataColumn then bind it to a Combo
box??
Is the follwoing code right?
public static DataSet InsertParamsToDS(ReportParameter arrParams)
{
DataSet...
|
by: Hrvoje Voda |
last post by:
How to convert an array byte into string?
Hrcko
|
by: Andrew |
last post by:
Hi,
How do I convert an array to a string ?
What I did was convert a string to an array, after some manipulation, I want
to pass the value back to a string.
char setchecked;
setchecked =...
|
by: Sakharam Phapale |
last post by:
Hi All,
How to get the no of memory bytes allocated to the Array of type String?
Dim arrDetail(100,10) As String
Thanks and Regards
Sakharam Phapale
|
by: Jaime Stuardo |
last post by:
Hi all...
I'm trying to retrieve a SQLXML query using VB.NET. When I programmed in VB
6.0, I used Stream object to accomplish this which was trivial.
I cannot do the same thing in VB.NET. Here...
|
by: Allerdyce.John |
last post by:
Hi,
I am new to python. I would like to know how to use python regular
expression to substitute string value?
I have an input string like this:
x:11 y:0 w:760 h:19 area:14440 areaPerCent:0...
|
by: koval |
last post by:
Type mismatch error occured when calling HTML array elements through Request.form("txtlrno" & i) after self posting the form, please anyone help me
immediately because is in crisis.
|
by: dudeja.rajat |
last post by:
On Tue, Aug 19, 2008 at 12:20 PM, Fredrik Lundh <fredrik@pythonware.comwrote:
Fredrik,
My apology for any confusion created.
I read all the replies. In fact I'm thankful to you all guys who are...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |