loop in array in python


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting loop in array in python
# 1  
Old 04-16-2010
loop in array in python

Hi suppose in python I have a list(or array, or tuple, not sure the difference)
How do I loop inside the size of array.
The pseudo code is:

Code:
a=["d","e","f"]
for i = 1 to dim(a)
   print a
end

How to find the dimension in python?
Also, anyone has a handbook to suggest so I can borrow from library
# 2  
Old 04-16-2010
Code:
>>> a=["d","e","f"]
>>> len(a)
3
>>> for x in a:
...     print x
... 
d
e
f

If you're looking for a python tutorial, they have one @ http://docs.python.org/tutorial/

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to print python array in shell script loop.

I am unable to loop print a python string array in my unix shell script: ~/readarr.sh '{{ myarr }}' more readarr.sh echo "Parameter 1:"$1 MYARRAY= $1 IFS= MYARRAY=`python <<< "print ' '.join($MYARRAY)"` for a in "$MYARRAY"; do echo "Printing Array: $a" done Can you... (10 Replies)
Discussion started by: mohtashims
10 Replies

2. Programming

Python Paramiko multi threading to capture all output for command applied in loop

My issue : I am getting only last command output data in ouput file. Though comamnd "print(output)" displays data for all 3rd column values but the data saved in file is not what required it hs to be the same which is being printed by command"print(output)". Could you please help me to fix this,... (0 Replies)
Discussion started by: as7951
0 Replies

3. Shell Programming and Scripting

Trying to loop through folders and execute an existing python script.

I am trying to loop through lots and lots of folders and use the names of the folders to run a Python script which has parameters. E.g. -- setup_refs -n John -f England/London/Hackney/John -c con/con.cnf Normally to run `setup_refs` once from command line it's: `python setup_refs.py -n John... (3 Replies)
Discussion started by: Mr_Keystrokes
3 Replies

4. Shell Programming and Scripting

Python update variable name in for loop

Hello all, Not sure if this question has been answered already. I have some xml Element variable as below: child19 = core_elem_dcache.find('stat') child20 = core_elem_dcache.find('stat') child21 = core_elem_dcache.find('stat') child22 = core_elem_dcache.find('stat'Next I... (2 Replies)
Discussion started by: Zam_1234
2 Replies

5. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

6. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

7. Shell Programming and Scripting

Array with do while and if loop

Hi All, I am trying to run a do while for an array. And in the do while, I'm trying to get a user response. Depending on the the answer, I go ahead and do something or I move on to next element in the array. So far I can read the array, but I can't get the if statement to work. Any suggestions... (5 Replies)
Discussion started by: nitin
5 Replies

8. Programming

linux c, loop through 2d array?

I have a 2 d array that I need to loop through and check for a specific value in each variable... Im a little confiused on how to do this... #include stdio.h #include string.h main () { char arrary; memset(array,' ',sizeof(array)); for ????? { if ( array == ' ' ) { do... (2 Replies)
Discussion started by: trey85stang
2 Replies

9. Shell Programming and Scripting

Python- How to append to an array

Hello, I wrote the following in python that parses mathematical expressions and I'm trying to store the results in an array. For example, if I enter 3+4*2, the array should be . Unfortunately, I get the following: Can anyone help me figure out what is wrong? The tokenizer seems to work... (0 Replies)
Discussion started by: jl487
0 Replies

10. UNIX for Dummies Questions & Answers

Reading from while loop into an array

Hi I have something like cat $HOME/all_dirs | while read ln_old_dirs do if then echo "$ln_all_old_dirs" fi done As you know that the variable ln_all_old_dirs is not accessable from outside the... (2 Replies)
Discussion started by: ssuresh1999
2 Replies
Login or Register to Ask a Question