what is the difference between tuple and list

Page 1 of 1

6 Replies - 1827 Views - Last Post: 17 July 2012 - 07:49 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=279223&amp;s=5e9ca11f8348a96b079c2d8b4b756c6d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 sai_saketh92

Reputation: 0
• Posts: 12
• Joined: 10-May 12

what is the difference between tuple and list

Posted 14 May 2012 - 02:36 AM

what is the difference between tuple and list
Is This A Good Question/Topic? 0

Replies To: what is the difference between tuple and list

#2 atraub

• Pythoneer

Reputation: 828
• Posts: 2,236
• Joined: 23-December 08

Re: what is the difference between tuple and list

Posted 14 May 2012 - 05:44 AM

A tuple is immutable. This means that once the tuple is created, you can't add or remove elements from it, however, tuples can be processed more quickly.

Lists are mutable, you can add or remove elements from a list at any time.

When in doubt, use a list.

tuples are declared like this:
```a = (1,2,3,) #The extra comma is on purpose!

```

Lists are declared like this:
```a = [1,2,3]

```

This post has been edited by atraub: 14 May 2012 - 05:52 AM

#3 k3y

Reputation: 36
• Posts: 205
• Joined: 25-February 12

Re: what is the difference between tuple and list

Posted 17 July 2012 - 01:34 PM

sai_saketh92, on 14 May 2012 - 04:36 AM, said:

what is the difference between tuple and list

Here ya go
http://lmgtfy.com/?q...uple+and+a+list

• MrCupOfT

Reputation: 2298
• Posts: 9,535
• Joined: 29-May 08

Re: what is the difference between tuple and list

Posted 17 July 2012 - 01:43 PM

A Tuple can be made up of different datatypes

```("String", 0,)
```

#5 Simown

• Blue Sprat

Reputation: 322
• Posts: 650
• Joined: 20-May 10

Re: what is the difference between tuple and list

Posted 17 July 2012 - 01:52 PM

So can lists:

```["Another String", 1, 6.235]
```

• MrCupOfT

Reputation: 2298
• Posts: 9,535
• Joined: 29-May 08

Re: what is the difference between tuple and list

Posted 17 July 2012 - 03:42 PM

All the examples I seen make it look like that can only handle a single "type".

Dynamic typing argh
I'm more a statically typed, with a dash of functional coder.
I use a statically typed language where it immutable be default (mutability has stated explicitly).
So lists can be Immutable or mutable, but they can only contain objects of a particular specified type or a derivative of it.
Spoiler

This post has been edited by AdamSpeight2008: 17 July 2012 - 03:49 PM

#7 atraub

• Pythoneer

Reputation: 828
• Posts: 2,236
• Joined: 23-December 08

Re: what is the difference between tuple and list

Posted 17 July 2012 - 07:49 PM

Why would you resurrect a post that's been dead for two months just to add a lmgtfy link?

This post has been edited by atraub: 17 July 2012 - 07:52 PM