473,410 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Get item of a list by index

Hey,
I made a programm that looks like this, but I have a problem.
Expand|Select|Wrap|Line Numbers
  1. command = raw_input(">")
  2. fullcommand = command.split(" ")
  3. #example user input: >add 10 15
  4. if fullcommand.index("add") == 0:
  5. #how I want the rest to work:
  6. * * *a= fullcommand.getItem(1)
  7. * * *b= fullcommand.getItem(2)
  8. * * *c= a + b
  9. * * *print ("Result: *" + c)
  10.  
So what I need is a function that gets the item of a list which has the index 1 and the item with the index 2.
How does that work?
Peter
Feb 4 '12 #1

✓ answered by Smygis

Expand|Select|Wrap|Line Numbers
  1. command = raw_input(">")
  2. fc = command.split()
  3. if fc[0] == "add":
  4.     a = fc[1]
  5.     b = fc[2]
  6.     c = a + b
  7.     print "Result: " + c
Does exactly what you described that it should do. (I'm using python 2.7, you'll have to add parentheses at the print function if you are using python 3.x)

1 2506
Smygis
126 100+
Expand|Select|Wrap|Line Numbers
  1. command = raw_input(">")
  2. fc = command.split()
  3. if fc[0] == "add":
  4.     a = fc[1]
  5.     b = fc[2]
  6.     c = a + b
  7.     print "Result: " + c
Does exactly what you described that it should do. (I'm using python 2.7, you'll have to add parentheses at the print function if you are using python 3.x)
Feb 4 '12 #2

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

Similar topics

5
by: questions? | last post by:
I want to do list index function. >>> y= >>> y >>> y.index Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: unsubscriptable object It works with y=. Anyone has...
9
by: William Meyer | last post by:
hi, I need to get the index of an object in a list. I know that no two objects in the list are the same, but objects might evaluate as equal. for example list = for object in list:...
3
by: Prashant Mahajan | last post by:
Hi All, I am facing a problem regarding accessing the item list of an XML node in IE. While using the following code: for(test in XMLNode) {} I received this XML Node from AJAX's...
96
by: zzbbaadd | last post by:
What's with the index() function of lists throwing an exception on not found? Let's hope this is rectified in Python 3. If nothing else, add a function that doesn't throw an exception. There are a...
7
by: python101 | last post by:
My code s= for k in range(len(s)): st=s.count(s) if st>=2: print s.pop(s.index(s)) Traceback (most recent call last):
3
by: Riccardo Murri | last post by:
Hello, I have some code that stops when trying to find a graph in a list of similar graphs:: (Pydb) list 110 try: 111 canonical = self.base 112 except ValueError: 113 ...
2
by: Georgy Panterov | last post by:
I am a relatively new python user. I am writing an economic simulation of acard-game. The simulation runs fine for a few iteration but then it gives an error of "list index out of range." The...
5
by: Mr.SpOOn | last post by:
Hi, is there any way to search elements in a list using wildcards? I have a list of various elements and I need to search for elements starting with 'no', extract them and put in a new list. I...
2
by: Chriskim | last post by:
I wrote a program that uses PyQt4, mathplotlib to generates graphs. I made a executable file using Py2exe. Everything is working fine, but when I exit from my program, a window message pops...
1
by: Karen Rosen | last post by:
This is my first program of any sort I am getting this error File "karenrosen5.py", line 162, in <module> record.append(triad("NoReleve",line)) File "karenrosen5.py", line 115, in triad...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.