Reputation: 145 Stalwart
- Active Posts:
- 275 (0.24 per day)
- 18-January 11
- Profile Views:
- Last Active:
- Feb 13 2013 07:28 AM
- OS Preference:
- Favorite Browser:
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- Your Car:
- Who Cares
- Dream Kudos:
Posts I've Made
Posted 8 Feb 2013Ah, fair enough. Heh, I'm still mostly using Python 2.
Anyway, I'd actually suggest defining __lt__ for the linked list, rather than the node. For instance, you could compare the lengths:
#A linked list class class SingleSortedLinkedList : #constructor def __init__ (self) : self._size = 0 self._head = None # ... # Compare linked lists by size. def __lt__(self,other): return len(self) < len(other)
Posted 8 Feb 2013Well... Simply make an empty linked list, and then insert linked lists in it.
outer_list = SingleSortedLinkedList() inner_list1 = SingleSortedLinkedList() inner_list2 = SingleSortedLinkedList() outer_list.insert(inner_list1) outer_list.insert(inner_list2)
Of course, when your linked list is sorted, you'll need to make it so that linked lists can be compared too (otherwise, how will you know where to insert?). This can be done by overriding the __cmp__ method. How you want to compare them is up to you, of course.
Posted 29 Jan 2013I believe the #\ is just Lisps way of saying "this is a char". Like, if it was just (h e l l o), how would you know if h was a char or an atom?
Posted 19 Jan 2013What darek9576 said - or I'll just tell you, cause it's not a long explanation. break breaks out of loops. There, that's it. So you just put "break" in your code, wherever you want to exit the loop. Like this:
import random while True: print("I'm stuck in a loop!") if random.randrange(0,10) == 4: break print("Yay, I got out of the loop")
Posted 17 Jan 2013I didnt even know that you can do datatypes like this, but then again, its like my second day and everything ive done so far has been on a chalk board
I can thoroughly recommend getting an interpreter and typing stuff in to see what happens.
e: Actually, here ya go.
- Member Title:
- D.I.C Regular
- 21 years old
- February 10, 1993
- Programming, reading (fantasy books), writing, music.
- Programming Languages:
Know pretty well:
Know a bit of: