472,992 Members | 3,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

how to write an array using python

Im new to the python programming and I wanted to know how to write an array using python
Jun 12 '07 #1
6 13113
Motoma
3,237 Expert 2GB
Im new to the python programming and I wanted to know how to write an array using python
Expand|Select|Wrap|Line Numbers
  1. arr = [1, 2, 3, 'four', [5, 6]]
  2.  
Jun 12 '07 #2
Thanks, one more thing how do you uss a for loop to print out lines with the line number, followed by the word
Jun 12 '07 #3
ilikepython
844 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. arr = [1, 2, 3, 'four', [5, 6]]
  2.  
Yea, just wanted to add that python has other array-like data types too:

Tuples are like lists except they can't be modified (immutable):
Expand|Select|Wrap|Line Numbers
  1. myTup = (1, 2, 3, "string", (5, 6), ["string2", 9])
  2.  
Dictionaries are like the C++ maps, they store corresponding values:
Expand|Select|Wrap|Line Numbers
  1. myDict = {"val":6, "val2":8, "val3":10}
  2.  
Jun 12 '07 #4
ilikepython
844 Expert 512MB
Thanks, one more thing how do you uss a for loop to print out lines with the line number, followed by the word
You can use enumerate():
Expand|Select|Wrap|Line Numbers
  1. lines = ["This is the first line", "This is the second line"]
  2.  
  3. for (lineNum, line) in enumerate(lines):
  4.     print lineNum + 1, line                        # enumerate returns the index which starts at zero
  5.  
or the index function of lists:
Expand|Select|Wrap|Line Numbers
  1. lines = ["This is the first line", "This is the second line"]
  2.  
  3. for line in lines:
  4.     print lines.index(line) + 1, line
  5.  
Jun 12 '07 #5
Thank you so mush you been a lot of help, im gonna check it and see if it works
Jun 12 '07 #6
bartonc
6,596 Expert 4TB
Thank you so mush you been a lot of help, im gonna check it and see if it works
I must ask that you please follow the Posting Guidelines for future posts on this site.

Thanks for joining.
Jun 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JW | last post by:
Hi, Below is a description of what I would like to do. Would someone tell me if it is possible and if so, how? I have an array (presumably 'large') that is mallocced in a C function and its...
0
by: Phil | last post by:
Hi, I don't understand this strange behaviour: I compile this code : #include <Python.h> #include"Numeric/arrayobject.h" static PyObject *
8
by: Bo Peng | last post by:
Dear list, I am writing a Python extension module that needs a way to expose pieces of a big C array to python. Currently, I am using NumPy like the following: PyObject* res =...
2
by: Albert Tu | last post by:
Hi, I am learning and pretty new to Python and I hope your guys can give me a quick start. I have an about 1G-byte binary file from a flat panel x-ray detector; I know at the beggining there...
3
by: Albert Tu | last post by:
Dear there, We have an x-ray CT system. The acquisition computer acquires x-ray projections and outputs multiple data files in binary format (2-byte unsigned integer) such as projection0.raw,...
10
by: Pierre Thibault | last post by:
Hello! I am currently trying to port a C++ code to python, and I think I am stuck because of the very different behavior of STL iterators vs python iterators. What I need to do is a simple...
6
by: Peter Wuertz | last post by:
Hi, I'm writing a C module for python, that accesses a special usb camera. This module is supposed to provide python with data (alot of data). Then SciPy is used to fit the data. My question...
4
by: DeveloperX | last post by:
I am trying to figure out how to rewrite the following chunk of code in Python: C source typedef struct PF { int flags; long user; char*filename;
8
by: Santiago Romero | last post by:
Hi :) First of all, I must apologize for my poor english :) I'm starting with python and pygame and for testing (and learning) purposes I wrote an small "Map Editor" for a small game project...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.