Added: 2 years ago
From: thenewboston
Views: 98,509
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (295)

Sign In or Sign Up now to post a comment!
  • 0 is a number in python

  • example=[1,2,4,7,5]

    example[-1:0:-1]

    Output

    [5, 7, 4, 2]

    What is wrong here?

    the way I see it, count from -1(last element) to 0(first element) using -1(backwords with 1 increment) .. but then why first element gets skipped?

    This code example[::-1] works perfectly fine and gives out all numbers in rev order

  • [10:0:02]

    [4:]

    anything like that doesnt work for me.

  • ur a better teacher than google

  • hi, nice tut's but i dont find them usefull... plz could yu make a tutorial of how to make a bot that could maybe link to a flash game? ty for reading.

  • I have a question: when you create a variable or a list, it is stored on your hard drive, correct? For how long is it stored/where is it stored? does it go away when you close python or will it stay there forever until it is deleted?

  • You could use

    >>>example[4:]

    this would give you all the numbers to the end of your list as well without using '-'

  • example[-5:10] WHy not?

  • 1:13 :|]

  • Java programmer here... PYTHON IS SUPER COOL! 6:05

  • This works in python 3.2.2 as well. Just so people know and don't freak out.

  • Becky, thanks for all your videos. Well done. I am a fan.

  • Just to be clear, when splitting , it goes

    [Location: Excluded End Location: Increment]

    right?

    EX:

    example = [0,1,2,3,4,5,6,7,8,9]

    print example[2:9:2] ##Location 2 is 2, Excluded Ending Location 9 is 9, and it Increments by 2.

    I'm only asking, because the choice in numbers for example is somewhat confusing because it makes people think that you can actually type the numeric value instead of the location in the list... at least that's how I first perceived it.

  • why do I  always understand fucky at the beginning?

  • at my last comment i wrote this and without watching further in i learnt that thats what you did sorry

  • if you want the whole list (1,2,3,4,5,6,7,8,9)

    instead of writing 1:10 you can write [1:] and it will do the whole list

  • @rednut416 Actually, you can just type example, and it'll do the same thing. Even faster

  • BAM! roasted toasted!

    ^ def saying that now..

  • I get 5-8 when i type 4:8...

  • @CycloneGaming1

    Compilers-- or in this case interpreters-- don't lie. Therefore you know you did something wrong, even though I bet you can't possibly imagine what that was. Welcome to programming.

  • Besides writing [:x] (x being any index) when you know that indexing starts at 0 allways so writing [0:x] will give you all the values from the beggining up to x.

  • you dont have to use example[:] to see your whole list you can just type the name of your list

  • ill name it example cuz thats how creative i am! lmao XD

  • lool have to admit quite simple, made a pokemon one (why pokemon, who knows)

  • example IS example[:]

    How is that a shortcut?

  • @walkerneo

    Really? Of course it's not a shortcut. That was just his way of explaining that it is a method of getting the whole list without putting in the first and plus one indexes. I guess you haven't noticed Bucky isn't really precise with his use of language, which is not only fine but maybe even helpful with this crowd. What I find amusing if you're taking issue with this and not everything else he says "wrong" then it must be that you're not catching all of those others things.

  • @PoorRichardSaunders

    and by "list" I actually meant to say "sequence" since I believe that is what this data type is termed in Python. 

  • @PoorRichardSaunders example[:] is useful if you want to make a copy of a list.

    for example, copy = example would make both names point to the same list while copy = example[:] will create a copy of example and assign it to the variable copy

  • For example, and this is the last comment I'll make in response; but I finished watching the rest of the video, and it's too good to ignore; he keeps saying "counting backwards". To me saying "short cut" was less egregious--- and here I am being facetious, because like I said there is nothing really wrong with it, and maybe it's even helpful to people intimidated by programing-- because it's relatively true, then saying counting backwards when you really just mean inverse indexing.

  • @kashman74012345 -then the user could search for filenames by typing in the name of the file. But behind the scenes the software only knows the place number of the files.... As he was showing us if you type List [3] you will get whatever file was the 4th file in the list... The thing I'm wondering about is how do you create a GUI that makes sense to a human... Where a person can type in a filename and the software knows how to find it in the index.... Guess I gotta keep learning to find out

  • @kashman74012345 the file organizer idea makes sense... If someone wanted to create a type of librarian software to organize media files of some type such as jpegs or mp3 files... Each media file added to the library would be added to the list and indexed (given a number behind the scenes)

  • Where does the rubber meet the road? Where does all this stuff get applied... Why would I need to make a list in the first place? Let alone have to extract certain data from it.... Some real world examples of when, where and why these skills he is teaching come into play when writing real software would be helpful to a beginner like me... It's just as important as the "How"

  • @disnukka79 Well, im no expert here. but connected to a raw input it could play a key role in organizational tools.. i mean, raw_input for x and y which are plugged into the slicer.useful for a calender eh? Please enter the dates you would like to view. of course most of this would be alot of behind the scenes. it could also be used to make a file organizer. Such as between dates or any other sets of information. Just ideas. tell me if you see some of how this could be applied.

  • Alright I've made it through 10 of these vids and I'm still waiting for the "Why" to be answered... How is being covered but I need this stuff to be put in context... what am I going to be able to do with this stuff. If I spend the required amount of time learning this stuff what am I going to be able to do with it... Can I really make cool software with this stuff that actually does something

  • "Now I said that was the last thing I'm gonna teach you; I lied."

    Bwah ha ha I dunno why I thought that was funny

  • Do you have questions that come with the tutorials? It would be nice if you did cuz it gives us practice, y'know?

  • Do you have questions that come with the tutorials?

  • i defined the example as example[2,4,6,8,10,12,14,16]. And when I typed in example[2:6] it printed out [6,8,20,12].

    Why did this happen? Did I do something wrong?

  • @gethighfly no you got it right.

    let me give you a example:

    numbers = [0,1,2,3,4,5,6,7,8,9]

    now if you want to extract [2,3,4] you must type:

    numbers[2:5]

    becouse python starts counting with 0 NOT with 1. And when you type

    numbers[2:5] it means python reads position 2 (it doesn't matter what number it is in position) and numbers between position 2 (including position 2) and 5 but without position 5.

    I hope I was clear enough.

  • @TheCrazyshuffler1 Oh right! I missed that point! Thank you very much! You were very clear.

  • THUMBS UP IF YOU WANT BUCKY TO BE YOUR TEACHER!!!! bucky ftw!

  • @0:58 he Says do a semicolon (;) , But instead does a colon (:), The colon is right. I just got mislead by it :D.

  • Thanks for the videos, all I could find was how to make something and it does not explain anything. Your videos seem to explain things right, on to part 11 next :P

  • exampili

    

  • I wish I was as smart as Bucky

  • now if you do [4:9] it skips four and includes 9

  • it's a full colon :) not a semi

  • Anyone else bugged by the fact that bucky always says semicolon instead of colon?

  • Comment removed

  • Why not just do print example?

  • @zaxby19 Because we're trying to learn something new smartass

  • raw_input ( "dude youre like the greatest teacher ever")

  • @Destunner you mean print "dude youre like the greatest teacher ever" ?

  • its like setting a fixed range to the list

  • sloice

  • Colon, not semi.

  • And it means the one after the fourth position.

  • When Bucky said that 4 is the number it begins with, he meant it is the fourth position (or fith, as it starts with 0), not the number 4. If it were a,b,c,d,e,f,g,h,i,j, then it would start with e, as it is the fourth item, starting with 0.

  • Comment removed

  • 4:50

    You could just type example.

  • I still don't understand the idea of -5. Bucky explains that it's to count the order backwards. But in the video the numbers don't return backwards. they count up [5,6,7,8,9]. So, was using -5 exactly the same as using 5?

  • @blizteria negative counting starts with -1 from the end to the start.. while positive counting starts with 0 from start to end. So in this example .. example[-5] would be the same as example[5] coz it points to the same value .ie 5.

  • You LIAR!!!!!

  • Comment removed

  • @bubbleheadft i got python 2.7.1 and it works just like boston said; i got the list example = [0,1,2,3,4,5,6,7,8,9]

    then next line i typed in example[4:9] it gave the output [4, 5, 6, 7, 8] so yeah ^^"

  • @bubbleheadft I got Python 2.7.1 and for me it prints out the first number

  • @bubbleheadft 2.7.2 does it the right way.

  • @bubbleheadft Wrong. You probably just forgot to add "0" to the first section of your list.

    "Typing [4:9]..." This will give you what's inside index 4 and up to (but does not include) 9. The index number 4 is actually the 5th index in the list. This is because the starting index is 0 on most programming languages.

    I use 2.7.2 and everything works perfectly just perfect - so far.

  • @bubbleheadft wrong.

  • @bubbleheadft yes jaffze123 was right typically programiing language use 0 as the base array, not 1. Nevertheless, some use 1. But in this python, it use 0.

  • @bubbleheadft I'm using python 2.7.2 and typing [4:9] gives me the result: [4,5,6,7] as he says. Before vote up this comment check which result you have.

  • thax for the vid,,really helpful

  • you can also doo [4: ] that means include 4 up too the end of the list

    and [4:9] means include 4 go up to put dont include 9

  • i did it and when i did example[3:5] it said "syntaxError:invalid syntax" and the colen (:) was in red

  • don't watch zander101084 he just wants the views

    This guy here is better lets just stick with him

  • example; gives u your entire list as well

  • e-x-ample-ee

    lol

  • exam[1:3]

    [1, 2]

    

  • ex am palee

  • shortcut to getting the entire list([:])? can't you just write the name of the list and it will show up? It worked for me.

  • When you have a list of of integers how do you find the sum or difference of all the integers in the list?

  • if you have a list of integers how do you find the sum of all the integers in the list?

  • i tried a method using print, i first made the variable like this "fgame = ['cstrike','hl2dm','lol','fof'­]" so when i do "print "my favorite game is " + fgame[1]" it works saying "my favorite game is hl2dm" but now when i want to slice the list doing "print "my favorite games are " +fgame[0:3]" it gives me error because its not string the command, so i did "print "my favorite games are " + `fgame[0:3]`" it gives me "my favorite games are ['cstrike', 'hl2dm', 'lol']" how print without [,]?

  • @nosthertus around the fgame[0:3] dnt use quotations, use the tic (`) mark in the left hand corner of jeyboard

    ex.

    >>> fgame = ['cstrike', 'hl2dm', 'lol', 'fof']

    >>> print "my favorite games are" + `fgame[0:3]`

    >>> my favorite games are [cstrike, hl2dm, lol, fof]

    since u added the `(tick mark) instead of the '(single quote), it shud work

  • I've just done an searching algorithm like google, that searches for the most equal line to our search in a text. This program really works well

  • in python 2.7 slicing is different

    if you type example[4:8] for the list example=[1,2,3,4,5,6,7,8,9] there will appear the numbers [5,6,7,8] not [4,5,6,7]

  • @bruno7242 it's because he had a 0 in his example, look into that

  • @bruno7242 You have the much older version bud sorry but he has the newer version

  • @Gamsterjeff600 no actually bruno7242 has a newer version 2.7 bucky is using 2.6 i got the same problem following this video too [4 : 8] returns [5, 6, 7, 8] in the newer version :)

  • Comment removed

  • @Gamsterjeff600 nevermind i presume bruno made the same mistake i did.. i forgot to put 0 into the list and since it counts position and not the actual number when using slicing it gave me 5 as it was in the 4th position in my list.... bucky still is using python 2.6 tho :)

  • You might be able to make it clearer by using a list of something other than numbers

  • @72drummerboi think of a simple task you want to automate on the computer and code it!

  • @thechitowncubs lol. Coding is actually fun and pretty easy to me. Coding scripts in Source engine games like TF2 helped :D

  • @PeopleR2sensitive It's fun to me too :)

  • @PlasticPackage You probably aren't going have much success if you need to ask that

  • Hey, I need to know something. Am I going to need Flash? Or can I make programs using only Python?

  • you seriously should become a teacher

  • just example that you can print everything, like example[:]

    and you are awesome.

  • thx u dude .it s really helpful to me .

  • BAM. Roast it toast it.

    LOOOOOOOOOOOL

  • @KharionX why would you laugh out out out out out out out out out out out loud?

  • @JadedLeach Because he's awesome. ._.

  • Hey bucky, thanks for these tutorials! i've been programming in C++ on windows for over a year now(all thanks to your videos!), but I just moved over to ubuntu, and python is a great language for me to learn in ubuntu. could you make some videos on how to use WxWidgets or Boa Constructor to make interfaces for our python programs? it would be really awesome(not that your videos aren't great already. they are!). thanks!

  • 4:48 Bam bucky you are a guiness

  • Bucky,

    Your explanation is not exactly correct.  Counting starts with POSITION 0, and not 1. The numbers between [ ] are the positions that you want to retrieve.

  • @maciagt I noticed that too. Bucky, try to do it with characters and you'll see that you can't just write example[a:c]. As you said in your 9th video, we're working with indexes.

  • @maciagt His name is greg lol.

  • @maciagt he starts with a zero.

  • @maciagt He never says that position start at 1? He just chose to start his slice at 1

  • @maciagt he explained that the previous vid

    

  • @maciagt

    stfu

  • Your explanation is not exactly correct. Counting starts with POSITION 0, and not 1. The numbers between brzckets are the positions that you want to retrieve.

  • when using python 2.7.1, I did exmaple[ 4:8] and it gave me

    [5, 6, 7, 8]

  • there's something i dont understand. when you on the example list (example [0,1,2,3,4,5,6,7,8,9]), what difference does it make if i write: example [-5:] or example [5:]?

    the - sign doesnt change anything...

  • @romangod2009 In this particular example it doesn't. But if he'd use 4 and -4, he'd get example[4:]=[4,5,6,7,8,9] and example[-4:]=[6,7,8,9]

  • OR IS IT?

    lol

  • I think that your tutorials are great! They are helping my learn python very quickly. For this video, it was easier for me to use my previously created list 'family' instead of the list 'example' so the operators in the [] parameters aren't confused with the data in my list.

  • Comment removed

  • Damn bucky! thx:) I'm reading programing at school but I havent learned anything there compared to this. So thx, and your giving me good grades too!^^

  • от десяти до нуля и каждый раз по минус два=)

    thank you for tutorials!

  • Please don't reply to old comments like 4 months old.

  • @iChopBalls so replying to ones like this is ok? Just making sure

  • Oops, nevermind. My mistake. I started from 1, not 0.

    My bad!

  • I am having an issue with this tutorial. When I type, for example: example[1:4] I get as the result: [2, 3, 4]. The python is skipping the first number and I can't understand why. I am using:

    Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32

    I hope somebody can help me out.

    Thx guys

  • @Richardunn It stops. The indexing starts from 0 , so example[6] is actually 7, example[3] = 4, and you got the correct output: 4,5,6 :)

  • Comment removed

  • @Richardunn You excluded 0 from your example=[ ] sequence.

  • Hey Bucky, thanks for making these videos. They're really helpful! =]

  • i love u, tnx bro

  • BUCKY IS AWESOME! Thanks, this is so helpful.

  • man your the best in youtube!!!!!!!!!!!!

  • @Richardunn  still does your example should star from 0

    example=[0,1,2,3,4,5,6,7,8,9]

    example[3:6]

    [3,4,5]

  • Thumbs up if he is better than your teacher!

  • Where did you learn all this? Did you do a computer science class or something?

  • oh you mean this tutorial explains HOW TO SELECT A MINIATURE LIST FROM YOUR LIST......makes sense....thanks a million....

  • haha 3:34 is hilarious! xD

    great tutorials btw =)

  • got me in boiling thoughts n all to later surpise me with "or is it" LOL, u sneaky son of a bitch i love you, thanks for all.

  • He must be stinkin' rich, making such cool programs. Did your Hey bucky program get you a lot of money? :-) KUTGW

  • 0:58 square braces...

    Anyway, great vid bucky!

  • Can sb tell me where EXACTLY is slicing used? U know like a list of photos, a list of books or sth like that...

  • I love your tutorials. I have looked everywhere and even tried to find books, but your tutorials are the best. Thank you so much!!!!

  • You are cool man..... Bucky you rock.........

    Now I am feeling I can use python...... still only on 10 th hahaha!!!

  • Oh, wow. This is kinda like Matlab.

  • Great tutorial. Keep up the great work!

  • Hey just want to let you know that i just got into learning python today and with your tutorials it is seaming easier by the tutorial

  • this guy is a legand!!!! i have been "tring" to work with python 4 the last month and non of it has been making much sense but half hour of browsing tho theses vids and BAM i know python :) well worth watching them all :)

    once again thanks for all ur time spend on theses videos has made it so much easier 4 the rest of us :)

  • Hey, Bucky...

    Thanks for these python tutorials, they've really helped me learn the language. you're great!

  • this reminds me of ms excel

  • Is Python similar to Ruby in the sence that everything is an object?

  • Great video ! you are really good teacher.

  • Woah it's so easy to manipulate arrays in python! In Java you have you have to pull your spine out through your eye socket to make the array do that... In comparison of course...

  • u also have tutorials for VPython? cause i think this is much more interesting but very hard to understand everything. Would be pleased if u answer!

  • Thank you very much for making python very clear! I tried reading the book, I get et but not very clear. Again thank you for posting these tutorial!!!

  • tnx again, smooth, step by step

  • var[::-1] easy way to invert list

  • OMG you're videos are the best!!! I have looked all over the internet to find things to help me and finally I found you and now I can program!!!! YOU ARE THE BEST!!!!!!

  • i have been watching your videos up to this one when i started thinking, i know how to do the stuff i just don't know when to use it or anything like that. i just started computer programming and watching your videos. if anyone can help me, thanks

  • @72drummerboi

    Sommone needs to make assignments with solutions to go along with these tutorials. It helps one really learn and develop the material since they have to apply it to solving problems.

  • @72drummerboi what you need from here, you have to create a project. For example take a paper and write: Programm name, what the program shoud do and start creating it. example

    program "pdf from list"

    then you create a bunch of code to collect the data

    then u store the data into something (database, here u create a code to store stuff in it) or txt

    then u get a module to create a pdf from it

    OR you write a bunch of code to interact with another program to convert it (like open office) good luck!

  • @72drummerboi lets think hacking because its probably the easiest to explain. say you want a program that finds an ip adress and then connects. you would make a variable for the ip and make a program that finds an ip and puts it in that variable. then you create some code that can connect your computer to that ip, well as soon as you move to the next line of code, the ip is lost so that's where the variable comes in handy. then you tell the program to connect to that variable which has stored

  • @gjh33 I just read all that and it made me think " I'm still a retard "

  • the ip.where as lists are mainly for organizing variables. when there is really complex code you have alot of variables. mainly these are stored in lists to simplify things.

  • I'm sure he will get to that. Just keep watching.

  • @72drummerboi You could search for programming tasks, and then try them.

  • @72drummerboi That's exactly how I am here at the University of Kentucky. Have you started writing your own programs yet?

  • @72drummerboi Best way i think is to think a program, just think it through in your head and think what do i want it to do. Then after this think how to solve it and then just solve the problem. Maybe start from something simple, i don't know... have for example 10 questions and each time you get a question right you get 1 point. At the end you will see how many points you got. That was one of the first independent tasks i made and i think it helped a lot to get to solve your own problems