Python Forum
Very beginner but please help!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Very beginner but please help!
#1
Hi, I am following a set of exercises, and I got stuck a bit on this one:
Write a function that returns the first and last elements of a list.

My code worked when the list was set, but when I use randomly created list, the command returns the whole list twice.
import random


def listing():
    list = [random.sample(range(1,100),10)]
    return [list[0], list[-1]]

print(listing())
Can you please check?:)

thurpe
Reply


Messages In This Thread
Very beginner but please help! - by thurpe - Jul-31-2018, 03:50 PM
RE: Very beginner but please help! - by buran - Jul-31-2018, 04:00 PM
RE: Very beginner but please help! - by thurpe - Jul-31-2018, 04:04 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020