¡Te damos la bienvenida a este reto!

1

Empezando con Python desde 0

Día 1

2

Variables, funciones y sintaxis básica

3

Tipos de datos: Numbers, Strings y Diccionarios

4

Playground - Retorna el tipo

Día 2

5

Operadores

6

Playground - Calcula la propina

Día 3

7

Condicionales

8

Playground - Averigua si un año es bisiesto

9

Ciclos

10

Playground - Dibuja un triangulo usando bucles

Día 4

11

Listas

12

Encuentra a los gatitos más famosos

13

Diccionarios

14

Obtén el promedio de los estudiantes

15

Tuplas

16

Obten la información de los paquetes

Día 5

17

Calcula la cantidad de letras en una oración

18

Encuentra el mayor palíndromo

Día 6

19

Sets

20

Encuentre la intersección de conjuntos

Día 7

21

List comprehension

22

Encuentra palabras con dos vocales

23

Dictionary Comprehension

24

Calcula la longitud de las palabras

Día 8

25

Funciones Lambda

26

Filtra mensajes de un user específico

27

Higher order functions

28

Crea tu propio método map

Día 9

29

Manejo de Errores y excepciones

30

Maneja correctamente los errores

31

Maneja las excepciones

Día 10

32

Playground - Crea un task manager usando closures

Día 11

33

Lectura de archivos de texto y CSV

Día 12

34

Programación orientada a objetos

35

Crea un auto usando clases

Día 13

36

Abstracción en Python

37

Playground - Crea un sistema de carrito de compras

38

Encapsulamiento en Python

39

Playground - Encapsula datos de los usuarios

Día 14

40

Herencia en Python

41

Playground - Jerarquía de animales usando herencia

Día 15

42

Polimorfismo en Python

43

Playground - Implementa un sistema de pagos

Día 16

44

Estructuras de datos en Python

45

Playground - Crea tu propia lista en python

46

Hash tables en Python

47

Playground - Implementación de una HashTable para Contactos

Día 17

48

Maps en Python

49

Playground - Crea un task manager con Maps

Día 18

50

Singly Linked List en Python

51

Playground - Implementación de una singly linked list

Día 19

52

Stacks en Python

53

Playground - Implementación de un stack

Día 20

54

Queues en Python

55

Playground - Implementación de una queue

Día 21

56

¡Lo lograste!

No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Playground - Implementación de un stack

53/56

Aportes 17

Preguntas 0

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

o inicia sesión.


.
.
.
.
.
.

from node import Node

class Playlist:
  def __init__(self):
    # Tu código aquí 👇
    self.top = None
    self.bottom = None
    self.length = 0

  def addSong(self, song):
    # Tu código aquí 👇
    newSong = Node(song)
    if self.length == 0:
      self.top = newSong
      self.bottom = newSong
    else:
      newSong.next = self.top
      self.top = newSong
    self.length +=1  

  def playSong(self):
    # Tu código aquí 👇
    if self.top is None:
      raise Exception("No hay canciones en la lista")
    if self.top == self.bottom:
      self.bottom = None
    play = self.top
    self.top = play.next
    self.length -= 1
    return play.value

  def getPlaylist(self):
    # Tu código aquí 👇
    list = []
    if self.top is None:
      return list
    current = self.top
    while current:
      list.append(current.value)
      current = current.next
    return list 
class Node:
  def __init__(self, value):
    # Tu código aquí 👇
    self.value = value
    self.next = None
    pass

Mi aporte:
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

# node.py

class Node:
  def __init__(self, value):
    # Tu código aquí 👇
    self.value = value
    self.next = None
    pass
# main.py

from node import Node

class Playlist:
  def __init__(self):
    # Tu código aquí 👇
    self.top = None
    self.bottom = None
    self.length = 0
    pass

  def addSong(self, song):
    # Tu código aquí 👇
    newSong = Node(song)
    if self.length == 0:
      self.top = newSong
      self.bottom = newSong
    else:
      newSong.next = self.top
      self.top = newSong
    self.length += 1
    return self
    pass

  def playSong(self):
    # Tu código aquí 👇
    if not self.top:
      raise Exception('No hay canciones en la lista')
      # return None
    if self.top == self.bottom:
      self.bottom = None
    song = self.top.value
    self.top = self.top.next
    self.length -= 1
    return song
    pass

  def getPlaylist(self):
    # Tu código aquí 👇
    lSong = self.top
    listSongs = []
    while lSong:
      listSongs.append(lSong.value)
      lSong = lSong.next
    return listSongs
    pass

🛡️🛡️Escudo anti-spoilers🛡️🛡️

Mi solución al reto:

#main.py
from node import Node

class Playlist:
  def __init__(self):
    self.top = self.bottom = None 
    self.length = 0

  def addSong(self, song):
    newSong = Node(song)

    if self.top is None and self.bottom is None:
      print(f"ℹ️  Agregando la primera cancion (🎵 {song})")
      self.top = newSong
      self.bottom = newSong
    else:
      print(f"ℹ️  Agregando una cancion a la playlist (🎵 {song})") 
      lastTop = self.top
      self.top = newSong
      self.top.next = lastTop 
    self.length += 1 

  def playSong(self):
    if self.length <= 0:
      raise Exception("❗No hay canciones en la playlist")
    playing =  self.top.value

    nextSong = self.top.next
    if nextSong:
      print(f"⏭️  La siguiente cancion a reproducir es (🎵 {nextSong.value})")
    else:
      print(f"Esta es la ultima cancion, no tenemos más en la playlist.")
      
    self.top = self.top.next
    self.length -= 1

    if not self.top:
      self.bottom = None
    print(f"▶️  Reproduciendo: (🎵 {playing})")
    return playing

  def getPlaylist(self):
    playlist = []
    current_song = self.top

    while current_song:
      playlist.append(current_song.value)
      current_song = current_song.next
    
    return playlist

SPOILER
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.


.
.
.
.
.
.
.
.
.
.

Mi código:

#  node.py
class Node:
    def __init__(self, value):
        self.value = value
        self.next = None
#  main.py
from node import Node

class Playlist:
    def __init__(self):
        self.top = None
        self.bottom = None
        self.length = 0

    def addSong(self, song):
        new_node = Node(song)
        if not self.top:
            self.top = new_node
            self.bottom = new_node
        else:
            new_node.next = self.top
            self.top = new_node
        self.length += 1

    def playSong(self):
        if self.length == 0:
            raise Exception("No hay canciones en la lista")
        
        song = self.top.value
        if self.top == self.bottom:
            self.bottom = None
        self.top = self.top.next
        self.length -= 1
        return song

    def getPlaylist(self):
        playlist = []
        current = self.top
        while current:
            playlist.append(current.value)
            current = current.next
        return playlist

class Node:
  def __init__(self, value):
    self.value = value
    self.next = None

from node import Node

class Playlist:
  def __init__(self):
    self.top = None
    self.bottom = None
    self.length = 0

  def addSong(self, song):
    newSong = Node(song)
    if self.top == None and self.bottom == None:
      self.top = newSong
      self.bottom = newSong
    else:
      newSong.next = self.top
      self.top = newSong
    self.length += 1


  def playSong(self):
    if self.playlistVoid():
      raise Exception("No hay canciones en la lista")
    if self.top == self.bottom:
      self.bottom = None
    playing_song = self.top
    self.top = self.top.next
    self.length -= 1
    return playing_song.value

  def playlistVoid(self):
    return self.length == 0

  def getPlaylist(self):
    songs = [self.playSong() for i in range(self.length)]
    return songs


.
.
.
.
.
.
.
.
.
.
.


Estuvo divertido el reto, aquí les va mi aporte:

class Node:
  def __init__(self, value):
    self.value = value
    self.next =None 
from node import Node

class Playlist:
  def __init__(self):
    self.top =None
    self.bottom =None
    self.length = 0

  def addSong(self, song):
    new_song = Node(song)
    if self.length == 0:
      self.top = new_song
      self.bottom = new_song
    else:
      new_song.next = self.top
      self.top = new_song
    self.length += 1

  def playSong(self):
    if not self.top:
      raise Exception("No hay canciones en la lista")
    if self.top == self.bottom:
      self.bottom =None
    popped_node = self.top
    self.top = self.top.next
    self.length -= 1
    return popped_node.value

  def getPlaylist(self):
    playlist = []
    if not self.top:
      return playlist
    current_song = self.top
    playlist.append(current_song.value)
    while current_song.next:
      current_song=current_song.next
      playlist.append(current_song.value)
    return playlist

playlist = Playlist()

playlist.addSong("Bohemian Rhapsody")
playlist.addSong("Stairway to Heaven")
playlist.addSong("Hotel California")

print(playlist.getPlaylist()) 
class Node:
    def __init__(self, value):
        self.value = value
        self.next = None
from node import Node

class Playlist:
    def __init__(self):
        self.top = None
        self.bottom = None
        self.length = 0

    def addSong(self, song):
        new_node = Node(song)
        if self.length == 0:
            self.top = new_node
            self.bottom = new_node
        else:
            new_node.next = self.top
            self.top = new_node
        self.length += 1

    def playSong(self):
        if not self.top:
            raise Exception("No hay canciones en la lista")
        if self.top == self.bottom:
            self.bottom = None
        popped_node = self.top
        self.top = self.top.next
        self.length -= 1
        return popped_node.value

    def getPlaylist(self):
        play_list = []
        current_node = self.top
        while current_node:
            play_list.append(current_node.value)
            current_node = current_node.next
        return play_list

Solución 😄…
.

.
.
.
.
Node:

class Node:
  def __init__(self, value):
    self.value = value
    self.next = None

Main:

from node import Node

class Playlist:
  def __init__(self):
    self.top = None
    self.bottom = None
    self.length = 0

  def addSong(self, song):
    new_song = Node(song)
    if self.length == 0:
      self.top = new_song
      self.bottom = new_song
    else:
      new_song.next = self.top
      self.top = new_song
    self.length += 1

  def playSong(self):
    if not self.top:
        raise Exception("No hay canciones en la lista")
    if self.top == self.bottom:
        self.bottom = None
    song = self.top.value
    self.top = self.top.next
    self.length -= 1
    return song

  def getPlaylist(self):
    songList = []
    actual = self.top
    while actual:
      songList.append(actual.value)
      actual = actual.next
    return songList

Mi solución 💻 🐍


.
.
.
.

node.py

class Node:
  def __init__(self, value):
    self.value = value
    self.next = None

main.py

from node import Node

class Playlist:
  def __init__(self):
    self.top = None
    self.bottom = None
    self.length = 0

  def addSong(self, song):
    new_song = Node(song)
    if self.length == 0:
      self.top = new_song
      self.bottom = new_song
    else:
      new_song.next = self.top
      self.top = new_song

    self.length += 1

  def playSong(self):
    if self.length == 0:
      raise Exception("No hay canciones en la lista")

    played_song = self.top.value
    if self.top == self.bottom:
      self.top = None
      self.bottom = None
    else:
      self.top = self.top.next

    self.length -= 1
    return played_song

  def getPlaylist(self):
    if self.length == 0:
      return []

    play_list = []
    current = self.top

    while current:
      play_list.append(current.value)
      current = current.next

    return play_list
playlist = Playlist()
playlist.addSong("Bohemian Rhapsody")
playlist.addSong("Stairway to Heaven")
playlist.addSong("Hotel California")

print(playlist.playSong())  # Output: "Hotel California"
print(playlist.playSong())  # Output: "Stairway to Heaven"
print(playlist.playSong())  # Output: "Bohemian Rhapsody"
print(playlist.playSong())  # Output: Error: No hay canciones en 
test_add_song_to_empty_playlist

test_add_song_to_non_empty_playlist

test_throw_error_if_playlist_is_empty

test_plays_and_removes_top_song_from_playlist

test_returns_empty_array_for_empty_playlist

test_returns_array_of_songs_in_reverse_order_of_addition

¡Felicidades, todas las pruebas pasaron!

Node file

class Node:
  def __init__(self, value):
    self.value = value
    self.next = None

Main file

from node import Node

class Playlist:
  def __init__(self):
    self.top = None
    self.bottom = None
    self.length = 0

  def addSong(self, song):
    new_node = Node(song)
    if self.length == 0:
      self.top = new_node
      self.bottom = new_node
    else:
      new_node.next = self.top
      self.top = new_node
    self.length += 1

  def playSong(self):

    if not self.top:
      raise Exception(
        "No hay canciones en la lista"
        )

    if self.top == self.bottom:
      self.bottom = None
    popped_node = self.top

    self.top = self.top.next
    self.length -= 1
    return popped_node.value

  def getPlaylist(self):
    current_node = self.top
    songs_list = []
    
    if current_node:
      while current_node:
        songs_list.append(current_node.value) 
        current_node = current_node.next      
    return songs_list

Mi solución:
+
+
+
+
+
+
+
+

class Node:
  def __init__(self, value):
    # Tu código aquí 👇
    self.value = value
    self.next = None
    
from node import Node

class Playlist:
  def __init__(self):
    # Tu código aquí 👇
    self.top = None
    self.bottom = None
    self.length = 0
    

  def addSong(self, song):
    # Tu código aquí 👇
    new_node = Node(song)
    if self.length == 0:
      self.top = new_node
      self.bottom = new_node
    else:
      new_node.next = self.top
      self.top = new_node
    self.length +=1
    

  def playSong(self):
    # Tu código aquí 👇
    if not self.top:
      raise Exception('No hay canciones en la lista')
    if self.top == self.bottom:
      self.bottom = None
    popped_node = self.top
    self.top =self.top.next
    self.length -=1
    return popped_node.value

  def getPlaylist(self):
    # Tu código aquí 👇
    if self.length == 0:
      return []
    nodes = []
    current_node = self.top
    while current_node:
      nodes.append(current_node.value)
      current_node = current_node.next
    return nodes  

o
o
o
o
o

class Node:
  def __init__(self, value):
    self.value = value
    self.next  = None

class Playlist:
  def __init__(self):
   self.top    = None
   self.botton = None
   self.length = 0


  def addSong(self, song):
    newNode = Node(song)
    if self.botton == None:
      self.botton = newNode
      self.top = newNode  
    else:
      newNode.next = self.top
      self.top = newNode    
    self.length += 1

  def playSong(self):
    if self.top == None:
      raise Exception("No hay canciones en la lista")
    else:
      apuntador = self.top
      cancion = self.top.value
      self.length -= 1
      if self.length == 0:
        self.bottom = None
        self.top = None
      else:
        self.top = self.top.next
      del apuntador
      return cancion   


  def getPlaylist(self):
    lista = []
    apuntador = self.top
    while apuntador != None:
      lista.append(apuntador.value)
      apuntador = apuntador.next
    return lista


playlist = Playlist()

print(playlist.getPlaylist())

playlist.addSong("Bohemian Rhapsody") 
print(playlist.getPlaylist())

playlist.addSong("Stairway to Heaven") 
print(playlist.getPlaylist())

playlist.addSong("Hotel California")
print(playlist.getPlaylist())

print(playlist.playSong())
print(playlist.getPlaylist())

print(playlist.playSong())
print(playlist.getPlaylist())

print(playlist.playSong())
print(playlist.getPlaylist())

print(playlist.playSong())




.
.
.
.
.

undefined