11

I want to divide a tuple by an integer. I am expecting something like this:

tuple = (10,20,30,50,80)
output = tuple/10
print(output)
output = (1,2,3,5,8)
normanius
  • 6,540
  • 4
  • 42
  • 72
pedram.py
  • 171
  • 1
  • 1
  • 5
  • 4
    I want to help you by closing your question in order to give you a chance to try it by yourself before getting a ready solution. – Maroun Apr 03 '16 at 14:27
  • 1
    Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve). – idjaw Apr 03 '16 at 14:28
  • a Thermal conductivity simulator – pedram.py Apr 03 '16 at 14:30
  • pedram.py: This has already been asked and answered. Please see http://stackoverflow.com/a/8244949/914547 – Rahul Purush Apr 03 '16 at 14:30
  • Another similar asked and answered post: http://stackoverflow.com/questions/1781970/multiplying-a-tuple-by-a-scalar – Ben Lindsay Apr 03 '16 at 14:31
  • i want to tuple not list – pedram.py Apr 03 '16 at 14:31
  • 4
    But people, take it easy with the downvotes! I think he/she gets the point after 1 or 2 – Ben Lindsay Apr 03 '16 at 14:32
  • @pedram.py Then see the link I posted above. The answer gives a tuple. – Ben Lindsay Apr 03 '16 at 14:33
  • i try this but it dont worked – pedram.py Apr 03 '16 at 14:35
  • 1
    @BenLindsay There's nothing wrong with downvotes, they are there to tell you that something 's wrong with your post. Bad posts *should* be downvoted. This post's quality is very bad, it should be even deleted. – Maroun Apr 03 '16 at 14:38
  • @pedram.py Please either edit your question or delete this one and start a new one to show what you tried and what the result was. All the downvotes you got (not from me) were because you asked a question that was already answered and didn't explain your attempts to solve the problem. – Ben Lindsay Apr 03 '16 at 14:38

2 Answers2

12

Basically the same as this answer by Truppo.

>>> t = (10,20,30)
>>> t2 = tuple(ti/2 for ti in t)
>>> t2
(5, 10, 15)
Ben Lindsay
  • 1,456
  • 1
  • 18
  • 43
9

may be you could try if is a numbers tuple:

numberstuple = (5,1,7,9,6,3)
divisor= 2.0
divisornodecimals = 2

value = map(lambda x: x/divisor, numberstuple)
>>>[2.5, 0.5, 3.5, 4.5, 3.0, 1.5]
valuewithout_decimals = map(lambda x: x/divisornodecimals, numberstuple)
>>>[2, 0, 3, 4, 3, 1]

or

value = [x/divisor for x in numberstuple]
Milor123
  • 518
  • 4
  • 20