6 Replies - 1318 Views - Last Post: 17 July 2012 - 07:49 PM Rate Topic: -----

#1 sai_saketh92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • 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

Was This Post Helpful? 2
  • +
  • -

#3 k3y  Icon User is offline

  • D.I.C Head

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

Re: what is the difference between tuple and list

Posted 17 July 2012 - 01:34 PM

View Postsai_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
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,464
  • 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,)

Was This Post Helpful? 0
  • +
  • -

#5 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • 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]

Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,464
  • 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 :wank:
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

Was This Post Helpful? 0
  • +
  • -

#7 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1