Тёмный

Learn to Program 6 : Lists 

Derek Banas
Подписаться 1,3 млн
Просмотров 66 тыс.
50% 1

Опубликовано:

 

28 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 259   
@thenewboston
@thenewboston 8 лет назад
Nice video, thanks Hoss!
@derekbanas
@derekbanas 8 лет назад
Thank you for the very nice compliment :) From the King of RU-vid Tutorials! I greatly appreciate it.
@tilakmadichettitheappdeveloper
Holy ! He's got a million subs man :)
@MadMax-rl6bt
@MadMax-rl6bt 6 лет назад
Wow amazing to see u both complementing each other!!!
@joelokhonjo4790
@joelokhonjo4790 2 года назад
Thank you Derek for such an amazing tutorial. However, I've realized that the outer while loop should have been while i > 0 and not while i > 1 because it still has to check for the last time, if you use > 1 there are some values that return the value in index 0 greater than the one in index 1
@guksungan1267
@guksungan1267 8 лет назад
12:43 the order is wrong because the code's outer loop is while i > 1: when it should be while i > 0: or while i:
@toddtao5259
@toddtao5259 8 лет назад
yeah, i think so too, i think it should be while i > 0, because that code loses one more round.
@veganath
@veganath 7 лет назад
Yes if the random list has the lowest value at the end then the sort will be incorrect. So it needs to be: while i>0 OR while i>=1
@andersduus3605
@andersduus3605 6 лет назад
Thank you! Was wondering what did wrong.
@arthurschopenhauer9308
@arthurschopenhauer9308 4 года назад
you can also just type while >= i: and this will work really well
@Hans_Wilsdork
@Hans_Wilsdork 8 лет назад
i am a recent graduate in programming, i remember doing the bubble sort in visual basic. syntax is a little different but logic is the same. great video!
@derekbanas
@derekbanas 8 лет назад
Thank you very much :) Congratulations on your degree!
@Hans_Wilsdork
@Hans_Wilsdork 8 лет назад
Thank you!
@Caustic13
@Caustic13 8 лет назад
Can't wait to dig into this series. I would be really interested in anything re: FRP, Elm or any of the others would be cool. Also, just want to say that my recent interviews have been going really well, the information you provide has helped me a ton. Looking forward to becoming a patron when I'm able.
@derekbanas
@derekbanas 8 лет назад
Great job on your interviews :) Sure I'll cover machine learning since so many people are interested in it
@boses5320
@boses5320 6 лет назад
Your videos are priceless, Trust me i am a construction engineer and i knew nothing about coding, i am learning from u and edx and that's all. I have a goal of building applications, data analysis and later ML and ultimately AI...... so big plans and u are helping me everyday, I wish i could say u how grateful i am.. Thanks again.
@derekbanas
@derekbanas 6 лет назад
Thank you for taking the time to write such a nice message :) I greatly appreciate it!
@BA10Lexie
@BA10Lexie 8 лет назад
multiplicationList = [[i * o for i in range(1, 10)] for o in range(1, 10)] multiplication table comprehension
@Dr1nc
@Dr1nc 8 лет назад
I love your tutorials. They're so efficient and easy to follow. I cannot wait for your c++ tutorials to begin. May i ask, if you have an ETA for it?
@derekbanas
@derekbanas 8 лет назад
Thank you :) Sorry, but I'm not sure. I just keep making videos until I feel I have covered most everything
@SmatfilmsT
@SmatfilmsT 8 лет назад
Great video. There is a way to improve the Bubble sort algorithm, sometimes the list or the array is already sorted so it would be unnecessary to look for elements that are not sorted, again. So we could break the loop and improve it a little bit even though the algorithm is much slower than others.
@derekbanas
@derekbanas 8 лет назад
Thank you :) Yes I know there are much better sorting algorithms. I covered this only because it is very simple to understand.
@acehanks
@acehanks 8 лет назад
Great video, didn't expect to be doing some algorithms already. Looking forward to more in the future
@derekbanas
@derekbanas 8 лет назад
Thank you :) Very soon we'll start solving problems similar to the Project Euler problems. By the end anyone that sticks with the tutorial should be quite good at solving programming problems.
@MadMax-rl6bt
@MadMax-rl6bt 6 лет назад
Sir, u r awesome. M just addicted to ur videos... Ur each and every video covers almost every topics. :)
@derekbanas
@derekbanas 6 лет назад
Thank you very much :) I'm happy you like them
@billblaney5758
@billblaney5758 5 лет назад
List Comprehension for the Win! I played around with using list comprehension and was able to build the enter multiplication table in a single statement: multiTable = [[(i+1) * (j+1) for j in range(9)] for i in range(9)] The print statement does not appear to support list comprehension (or, at least I haven't figured out how to use it).
@jacquesmutombombuyamba7217
@jacquesmutombombuyamba7217 6 лет назад
Hi Derek, thank you for the nice video. If you pause the video at 13:11 the sorting algorithm gives 2, 1, 4, 4, 5 where 1 should at the first index.
@jacquesmutombombuyamba7217
@jacquesmutombombuyamba7217 6 лет назад
The first while or the outer while should be while i > 0
@PureWaterSolutions
@PureWaterSolutions 8 лет назад
You made this on July 4th, you're a patriot! Thanks for the awesome videos
@derekbanas
@derekbanas 8 лет назад
Thank you :) I love making videos. I'll make one most any day of the year.
@angelinajolie3921
@angelinajolie3921 8 лет назад
Awesome Derek ! Suggestion: You could cover Algorithms and Data Structures you didn't do with Java such as: Graphs - I've read that Google and Facebook - at least in their early days were based off of graph data structures -That would be interesting. Thanks In Advance !
@derekbanas
@derekbanas 8 лет назад
Thank you :) I will completely cover algorithms this time
@LearnWithBahman
@LearnWithBahman 5 лет назад
@@derekbanas Where is Algorithm video of yours?Did you have time to do that? thanks for all of your videos.
@weezybusy
@weezybusy 8 лет назад
Enjoying these tutorials so much. Thank you, Derek!
@derekbanas
@derekbanas 8 лет назад
I greatly appreciate you telling me that :) When I start a new tutorial it is sometimes very hard to gauge if people are finding it useful. Thank you
@s3icc0
@s3icc0 7 лет назад
question to the random list: i printed the list for range of 100 values and noticed that each time the randomly generated number was already present in the list the position returned was related to the position for which the number was assigned for the first time. What if I really want each new random number also having a unique position in the list?
@Dr3bdu11ah
@Dr3bdu11ah 8 лет назад
i am very thankful for what present for us , i have one question : is the multidimensional the same with the list node in java ?
@derekbanas
@derekbanas 8 лет назад
You're welcome :) Yes this is just lists inside of lists
@russ6198
@russ6198 7 лет назад
Thanks! Great video, as usual. Here's a version that cleans up the output: mt = [[i * x for i in range(1, 10)] for x in range(1, 10)] for group in mt: s = "" # empty string for i in group: s = '{} {:>2s}'.format(s, str(i)) print(s)
@derekbanas
@derekbanas 7 лет назад
Thank you for sharing :)
@aviadomeisi4894
@aviadomeisi4894 6 лет назад
for line in range(1,10): print(f"when line = {line}") print([i*line for i in range(1,10)])
@Wendy58917
@Wendy58917 8 лет назад
The Video make python so interesting. Really like the small exercises during the video. Thanks!
@derekbanas
@derekbanas 8 лет назад
Thank you :) I'm very happy you liked it
@atemnkengasong6632
@atemnkengasong6632 7 лет назад
Hi Derek I've a little problem! So i was writing a code and i wanted to compare each of the values in my list with 2 but i keep getting error. This is what I did:num=[ input ("Enter a value:") for i in range (10)] for i in range (10): If num [0] < 2: print ("Not prime") else: ....i keep having an error message at: if num [0] < 2:Also, how do i create a class then declare a variable of type that class and make it a list?well in algorithm it's something like: Structure Student name: integer; Sex: char; Mark: real;Algorithm Student_Info Var S: Student [50];
@cyancoyote7366
@cyancoyote7366 8 лет назад
Awesome :) You should show us how to use multithreading, and tell us the things we should know about it :)
@derekbanas
@derekbanas 8 лет назад
Thank you :) I'll definitely cover that soon
@TheJacov
@TheJacov Год назад
Hey Derek, here's a weird glitch for you. I like to import math as m so I don't have to write out math, all the time, but still keep from cluttering up my namespace with all the math functions. Works fine most of the time, however, in the comprehension it was confusing your m with my m. somehow. I fixed the problem by changing your m to an n, then everything worked fine. I don't have any clue as to why it did that, but whatever works, I say!
@SiGnAtUrEaDD
@SiGnAtUrEaDD 7 лет назад
hey Derek! for the last question why do you need to create a 10 by 10 list when you only use up 9 by 9 spaces? This is my code: mul_table = [[0] * 9 for i in range(9)] for i in range(1, 10): for j in range(1, 10): mul_table[i][j] = '{} * {} = {}'.format(i, j, i * j) for i in range(1, 10): for j in range(1, 10): print(mul_table[i][j], end='|') print() when I run the code I get this error 'IndexError: list assignment index out of range'
@E_-_-
@E_-_- 7 лет назад
Your tutorial videos are really good. Thanks for making them.
@derekbanas
@derekbanas 7 лет назад
Thank you for the nice compliment :)
@mihaimonar2492
@mihaimonar2492 8 лет назад
I'm just putting this out there as another way of doing it. This was my way of creating a list of 9 lists of 9 elements as the multiplying table required,instead of a ten by ten list which doesn't use the first list (list number 0 at all and neither the first element (number 0) of each list) list=[[0]*9 for i in range(9)] for i in range(0,9): for j in range(0,9): list[i][j]=(i+1)*(j+1) print(list[i][j],end=",") print() print(list)
@derekbanas
@derekbanas 8 лет назад
Thank you for sharing :)
@wilbertraymundrayos4175
@wilbertraymundrayos4175 6 лет назад
Good day sir, I'm confused in the multi-dimensional list. if i initialized: multiDList = [[0]*4 for i in range(4)] this will create a 5x5 list with an initial value of 0. | 0 | 0 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 0 | what if I want to create a 5 rows with 3 columns each? | 0 | 0 | 0 | | 0 | 0 | 0 | | 0 | 0 | 0 | | 0 | 0 | 0 | | 0 | 0 | 0 | is it [[0]*2 for i in range(4)] or [[0]*4 for i in range(2)]
@rogeriosouza9288
@rogeriosouza9288 5 лет назад
Hi, computer starts counting from 0... so when you multiply the list by 4 ( you have 5 columns (0,1,2,3,4) )... same for the in range command! I hope I help you, even after some months lol
@rogeriosouza9288
@rogeriosouza9288 5 лет назад
In [[0]*4 for i in range(4)] [0]*4 is saying that the length of your list is 4... and in range(4), your are going to create 4 rows :) ... so it would be a 4x4 matrix. For 5 rows and 3 columns you should use: multiDList = [[0]*3 for i in range(5)]
@user-te7mu58z
@user-te7mu58z 9 месяцев назад
What an amazing tutorial! THANK YOU!
@squeebiebalmy8776
@squeebiebalmy8776 6 лет назад
This code below will output the same result as the one you shown. Is there any reason to have 2 for loops instead of 1 as shown below? Thanks! :) ---------------------------------------------------------------- multTable = [[0] * 10 for i in range(10)] for i in range(1, 10): for j in range(1, 10): multTable[i][j] = i * j print(multTable[i][j], end=", ") print()
@guoliangli8426
@guoliangli8426 8 лет назад
Although I am learning Phthon27, but I still found your video very systmetic and instructive. Thanks
@derekbanas
@derekbanas 8 лет назад
Thank you :)
@gaming_fun2317
@gaming_fun2317 5 лет назад
Derek, What do you think about my solution to the last problem? for i in range(1, 10): for ii in range (1, 10): print(i * ii, end=" ") print()
@erst3471
@erst3471 6 лет назад
Bubble sort: for i in range(0, len(randomList) - 1): for j in range(0, len(randomList) - 1): if randomList[j] > randomList[j+1]: randomList[j], randomList[j+1] = randomList[j + 1], randomList[j]
@bogdanpoznanic5627
@bogdanpoznanic5627 5 лет назад
for i in range(1,10): for j in range(1,10): new_list = [[j * i] * 10 for g in range(10)] print(new_list[i][j], end=", ") print()
@hamidurrahman3183
@hamidurrahman3183 6 лет назад
// just creating multipliction tables for i in range(1, 11): print("{}'s Multiplication table. ".format(i)) for j in range(1, 11): print("{} * {} = {}".format(i, j, i*j)) print("-"*15) //Your wanted way table = [[0 for i in range(11)] for j in range(11)] for i in range(1, 11): for j in range(1, 11): print(i*j, end=", ") table[i][j] = i*j print()
@NielsvanWijnen
@NielsvanWijnen 6 лет назад
Thank you so much for all these tutorials! You truly have a gift for explaining difficult things in an easy way. i see some 'incl me' had some difficulty understanding the part of: [[0] * 10 for i in range(10)] Hope i can breakdown what exactly is happening. If i understand it correctly, then derek has generated the following 10x10 multitable at the end of this tutorial: (you just don't see all the zero's because he adjusted and printed from [1,1] and up, instead of [0,0] and up. So it looks like a 9x9) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 0, 9, 18, 27, 36, 45, 54, 63, 72, 81, If you truly want to make the 9x9 table, then i think the code below might also work. Notice that in this case it will start in the [0,0] 'which derek showed in previous example is the very first box in the top left corner' and it wil put the number (0+1)*(0+1) = 1. which is exactly what we want for our first number. Hope i make sense and explained it correctly. multiDlijst = [[0]*9 for i in range(9)] for i in range(9): for j in range(9): multiDlijst[i][j] = (i+1)*(j+1) print(multiDlijst[i][j], end = ", ") print()
@MrSarky1992
@MrSarky1992 6 лет назад
Hi Derek, Hi All, What is the point of using the list() function with range when creating a list? The range function in itself creates a list right? So what is the difference between oneToTen = range(10) and oneToTen = list(range(10))? Thank you!
@MrSarky1992
@MrSarky1992 6 лет назад
In case anyone comes across this same question: the difference is that range(10) is a object of the range class, and the list(range(10)) is an object of the list class. So they have a different class type. This is critical when you for example are trying to access functions that are inside the list class (for example the insert function).
@KelvinNgera
@KelvinNgera 2 года назад
best understanding of how bubble sort works you are great
@derekbanas
@derekbanas 2 года назад
Thank you :) I'm very happy that I could help
@f.musterman5441
@f.musterman5441 8 лет назад
Derek you are awesome. please make videos about hibernate ORM and java persistence, neo4j, elastic search and bash
@derekbanas
@derekbanas 8 лет назад
Thank you :) I'll see what I can do. I made a Bash scripting tutorial ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-hwrnmQumtPw.html
@f.musterman5441
@f.musterman5441 8 лет назад
thanks a lot you are a life safer :) warm greetings from Berlin
@terraflops
@terraflops 8 лет назад
for others that like lists to be left to right: for i in numList: pass print(numList) and for the bubble sort, i like to have the starting random list: print(" random list:", numList)
@thewingdings1324
@thewingdings1324 7 лет назад
At 4:00 could you use enumerate instead of .index ()? I'm just learning how to make things efficient and everyone says enumerate is great for that
@MadMax-rl6bt
@MadMax-rl6bt 6 лет назад
We can also reduce the code- List=[1,2,3,4,5,6,7,8,9,10] for i in list: New_list=[i*j For j in range(1,11)] print(New_list)
@derekbanas
@derekbanas 6 лет назад
Thank you for sharing :)
@abdullahnoman8618
@abdullahnoman8618 7 лет назад
Bubble sort in simple "" Bubble Sort Algorithm @:param unsorted List @:return sorted List """ def bubbleSort(inpList): for i in reversed(range(len(inpList))): # Counting in reversed order for the outer loop for j in range(i): # Inner loop counting if inpList[j] > inpList[j + 1]: temp = inpList[j + 1] # storing a temp var inpList[j + 1] = inpList[j] # replacing with the bigger one inpList[j] = temp # implementing the temp var return inpList
@maeeen6078
@maeeen6078 8 лет назад
Your tutorials are awesome !
@derekbanas
@derekbanas 8 лет назад
Thank you very much :)
@zackgrey4472
@zackgrey4472 7 лет назад
Hey Derek! I have a question pertaining to lists, I want to make a database of sorts (I know MySQL is made for them but I want to try with python). So far what I did was collect user input and add it to list, however it doesn't save. Here is my code, all I could think of was use a library but I was curious if I could do it without a library. def main(): a = raw_input("Input something to add to list: ") dlist = [] dlist.append(a) print dlist while True: main() It adds variable a to the list but then it removes it every time, I'm trying to make it so that a would be permanently added to the list every time. Thank you!
@derekbanas
@derekbanas 7 лет назад
You could save the list of data to a file and then load it each time the program runs ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-EukxMIsNeqU.html
@zackgrey4472
@zackgrey4472 7 лет назад
Thank you! I started this series a couple months ago and have learned so much, your the best Derek!!!
@NorrisChukNorris
@NorrisChukNorris 8 лет назад
Nice, another one . I recently started learning programming and started with java, but after a while it was a bit confusing. Then i moved to these tutorials and it's going better. Thanks for making them. Btw to anyone who sees this: should I upgrade to windows 10?. I heard there were some issues so i didn't upgrade because I am fine with 8.1, but now there is not much time left so I'm thinking about upgrading. Is it better? And are there any real issues?
@derekbanas
@derekbanas 8 лет назад
Thank you :) I'm very happy that the videos are helping! I love Windows 10 by the way.
@shadk89
@shadk89 8 лет назад
you should check out MIT's course at edx for python.
@NorrisChukNorris
@NorrisChukNorris 8 лет назад
thanks for advice
@yuvigerstein
@yuvigerstein 7 лет назад
How does it feel to make the very best Python tutorials out there? :)
@derekbanas
@derekbanas 7 лет назад
Thank you for the nice compliment :)
@debjitchattopadhyay599
@debjitchattopadhyay599 7 лет назад
how can we maintain a fixed coloumn in the multiplication table that u created?
@kunstkritik
@kunstkritik 8 лет назад
Not that it is important at all but you did a small mistake with your BubbleSort as you can see with the result at 12:45 The outer loop should go while i > 0 and not i > 1, because when the last round starts with i = 2, j swaps the first two and then the third with the second but it can still occur that we would have to swap the first two again afterwards
@derekbanas
@derekbanas 8 лет назад
Whoops sorry about that. Thank you for pointing it out for anyone that may be confused
@pedroalmeida7066
@pedroalmeida7066 6 лет назад
Hey Derek in the last example maybe it is for ease of understanding and avoid summing 1 to i and j in the loop, but aren't you really creating a table with 10 lines and 10 rows when we only need 9 and ignoring the first line and the first row when filling it and printing it when in reallity we are creating and filling something like: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 0, 9, 18, 27, 36, 45, 54, 63, 72, 81, Sorry if i'm missing something or if i'm not being clear about what i'm talking about. Cheers and thanks a lot for all these videos
@izzyece707
@izzyece707 8 лет назад
literally, you are a bless :) thank you for your great efforts. what is the best book that explain the machine learning you think ?
@derekbanas
@derekbanas 8 лет назад
Thank you :) You're very welcome Python Machine Learning is very popular amzn.to/2az6W0V
@izzyece707
@izzyece707 8 лет назад
thank you very much, wish one day I'll be like you
@miodragniss
@miodragniss 8 лет назад
you're a great teacher! will django and web development with python be a part of this tutorial?
@derekbanas
@derekbanas 8 лет назад
Thank you :) Yes I'll cover Django
@miodragniss
@miodragniss 8 лет назад
Great, I can't wait :)
@andrewmuller5826
@andrewmuller5826 8 лет назад
any reason why you use the math pow function instead of writing **? eg 2 ** 3 = 8
@derekbanas
@derekbanas 8 лет назад
Just to show that the function is available
@_misterwhy
@_misterwhy 8 лет назад
Hi Derek ! First of all, thanks a lot for your knowledge ! Second: The language of Shakespeare is not my mother tong so … apologies ^^ But I have a little problem here : I try to know how many times (how many loops it'll need to do) will it take for the computer to make me a numlist like that : [1,2,3,4,5] with the random of course. My code : import random import math numlist = [] i = 0 while (numlist != [1,2,3,4,5]): for j in range(5): numlist.append(random.randrange(1,5)) i +=1 print(i, numlist) And if I put the "print(i, numlist)" in the while loop to see what's happening, I see that the numlist become too big. I tried also to find a shorter result, like numlist = [1], but one time it works, and the second it's crazy ^^ I hope that you'll anderstand it all ^^ Thx
@derekbanas
@derekbanas 8 лет назад
Hi, You're very welcome. This program will create a list of 5 values that are random between the values of 1 and 5. I hope it helps. import random numlist = [] # Cycle through each box in the list for i in range(5): # Generate a random value between 1 and 5 # and assign it to the current box in the list numlist.append(random.randint(1, 6)) print(numlist)
@_misterwhy
@_misterwhy 8 лет назад
That part I get it, what I want is : when the program create randomly a list with 5 numbers, from 1 to 5, and it will return for example : [1,4,5,3,3], [1,2,2,4,5] … but how many time do I have to run the program to get exactly [1,2,3,4,5] ? And I want to put the "How many time" into the "i". That's the goal of my program. Beter ? Thx again :)
@ricardohincapie1537
@ricardohincapie1537 4 года назад
Great tutorial. Thank you very much
@derekbanas
@derekbanas 4 года назад
Happy you liked it :)
@esnipeproduction
@esnipeproduction 8 лет назад
Hello Derek. I don't understand why we need this part : while i > 1 ? What does it do and why we need to decrement it by 1? BTW i really appreciate your videos! It helps me a lot.
@derekbanas
@derekbanas 8 лет назад
Thank you :) The out loop starts at the end of the loop and moves towards the beginning. That is why the i is being decremented each time.
@esnipeproduction
@esnipeproduction 8 лет назад
I still don't get the code. I'm watching the video over and over again, but I don't understand it. :(
@DurdenTyler3
@DurdenTyler3 8 лет назад
---Please note, there's an error in the code.--- Hi Derek! Thank you for your videos! They are awesome. I believe you have an error in your code. On 13:03 you can see that the list is not fully sorted (i.e '2' and '1' should switch places) The reason is 'while i > 1' should be 'while i > 0' on line 11. I think it would be helpful if you put some annotation-rectangular message about this. Thanks again!:)
@derekbanas
@derekbanas 8 лет назад
Thank you :) Sorry for the bug
@x10nd
@x10nd 8 лет назад
@derekbanas You could also do this? import random import math for i in range (5): randList =[] randList.append(random.randint(0,10)) print(randList[0]) ------------- MultTable = [[1] * 10 for i in range(10)] for i in range(1,10): for j in range(1,10): MultTable[i][j] = "{} x {}".format(i,j) if(j==1): print () print("-------Table of "+str(i)+"--------") print () print(MultTable[i][j]+" = "+str(i*j),)
@derekbanas
@derekbanas 8 лет назад
Thank you for the input :)
@Rich65501
@Rich65501 5 лет назад
Thank you Derek. You are bodacious
@Sipulikeittohomo
@Sipulikeittohomo 7 лет назад
My multidimensional list :) j = 1 MultList = [i * j for i in range(1, 10)] for i in range(1, 10): for j in range(1, 10): MultList = i * j print(MultList, end=", ") print()
@MrGurkentomate
@MrGurkentomate 8 лет назад
Last Problem is a lot easier with inline for loops, although it might be easier to understand the way you did it;) list = [[i * j for j in range(1,10)] for i in range(1,10)] print(list) Also, why did you not say anything about the way you can simply call print(list)? To explain lists it's obviously beneficial to use for loops over the elements, but in general one should simply use print(list) if possible
@derekbanas
@derekbanas 8 лет назад
Yes I did it the way I did to make the code more understandable. Teaching problem solving is my main goal. Sorry I didn't mention you can print lists with print(list). I'll show that in the next video. Thanks for the input :)
@doomygloomy1
@doomygloomy1 8 лет назад
have you tried running this a couple dozen times ? Sometimes (very rarely) it gives stuff like : Switch 3, 1, 3, 4, 6, END OF ROUND 3, 1, 3, 4, 6, And that's where the program ends. Is this supposed to happen (I don't think so)
@derekbanas
@derekbanas 8 лет назад
No that is strange. I'll try to reproduce the results
@johnkls4739
@johnkls4739 8 лет назад
Zoomba ,try this '' while i >= 1:''
@doomygloomy1
@doomygloomy1 8 лет назад
yes that was it thanks.
@hleek2003
@hleek2003 7 лет назад
can you use this for multi listing?
@SongSeeker7
@SongSeeker7 8 лет назад
Is there a way to create a closure in python? Or is there a way to create a static local variable in a function?
@derekbanas
@derekbanas 8 лет назад
Yes you can create closures in python. I'll cover that soon.
@SongSeeker7
@SongSeeker7 8 лет назад
awesome! :)
@edgarsanchez9583
@edgarsanchez9583 7 лет назад
Dear Derek, is it cool if I make notes about this set of tutorials in a github repo, of course giving you all due credit and pointing to the original source? I'm trying to document my progress...
@derekbanas
@derekbanas 7 лет назад
Yes most definitely. You don't need to give me credit. All of my code is free to use in any way
@edgarsanchez9583
@edgarsanchez9583 7 лет назад
Thank you man. Well even if it's free, "honor to whom deserves it" Cheers!
@craigsavage4586
@craigsavage4586 6 лет назад
# Made a one-liner. Thanks for the tutorials. multiTable = [[i * j for i in range(1, 10)] for j in range(1, 10)]
@itsbayahmed
@itsbayahmed 5 месяцев назад
Here is my solution: list = [1, 2, 3, 4, 5, 6, 7, 8, 9] for i in Blist: for m in range(1, 10): print(i * m, end=", ") print()
@mihaimonar2492
@mihaimonar2492 8 лет назад
Good morning Derek :)
@derekbanas
@derekbanas 8 лет назад
Good morning :)
@murifedontrun3363
@murifedontrun3363 5 лет назад
Creating a multidimensional array with 4 columns and 3 rows in which all elements are arbritary multidarray = [[int(random()*10) for i in range(4)] for j in range(3)]
@2271masoud
@2271masoud 8 лет назад
wicked. another great tutorial
@derekbanas
@derekbanas 8 лет назад
Thank you very much :)
@naveenagundeti4351
@naveenagundeti4351 7 лет назад
Hi Derek, i am wondering why this doesn't work. could you please help me? Thankyou randlist =[] for i in range(5): randlist[i]= random.randrange(1,9) print(randlist)
@FireClocks
@FireClocks 8 лет назад
I got a little confuse with the list of list and overall when the list part began. What does the j and i represent on multTable[i][j]? Is i the index and j the value? Although I didn't understand very well I got the result of the last problem right with this code: multi_table = [[0] * 10 for i in range(10)] for i in range(1, 10): for j in range(1, 10): k = j * (i + 1) multi_table[i][j] = "{}".format(k) for i in range(10): for j in range(10): print(multi_table[i][j], end=" ") print() but since you didn't use k and just did i * j can you explain me what am I understanding wrong here pls. Thanks, your tutorials are amazing xD!
@derekbanas
@derekbanas 8 лет назад
The i represents each row and the j represents the column of each row. This allows use to store information in a grid or matrix. I'm using k to store the value of the multiplication. I then store it in the grid.
@FireClocks
@FireClocks 8 лет назад
Ok, thanks for the help!
@nsv.2344
@nsv.2344 8 лет назад
Just curious how many more in this series?
@derekbanas
@derekbanas 8 лет назад
I will completely cover solving programming problems while also covering Python to the extent that people will be able to do most anything with it. It is going to be a long tutorial series.
@lbttewelde7121
@lbttewelde7121 Год назад
Thankyou was so helpful
@JannisAdmek
@JannisAdmek 8 лет назад
This is awesome, thank you so much!
@derekbanas
@derekbanas 8 лет назад
Thank you :) You're very welcome
@jaideepsingh206
@jaideepsingh206 7 лет назад
Solution to multi dimension list using list comprehensions- y = list(range(1,10)) multi_list = [[row*p for p in range(1,10) ] for row in y] multi_list #Display the multi dimensional list
@derekbanas
@derekbanas 7 лет назад
Thank you for sharing :)
@mahimsd7645
@mahimsd7645 7 лет назад
please provide a bunch of advanced Python tutorials .... as well a tutorial based only on Python practice examples ........
@superoxidedismutase5757
@superoxidedismutase5757 5 лет назад
Great stuff!
@derekbanas
@derekbanas 5 лет назад
Thank you :)
@ColtonPhillips
@ColtonPhillips 8 лет назад
awesome. Except when you used a temp swap in Python...
@derekbanas
@derekbanas 8 лет назад
Thank you :)
@tomasvallejos1609
@tomasvallejos1609 5 лет назад
here is my solution to the multiplication table problem utilizing list comprehension: values = list(range(1, 11)) multiplicationTable = [[i * j for j in values] for i in values]
@aayushdani8878
@aayushdani8878 8 лет назад
So when did you start to program?
@derekbanas
@derekbanas 8 лет назад
When I was 10 on a TRS-80 about 30 years ago
@reaganmaxwell9867
@reaganmaxwell9867 8 лет назад
+Derek Banas I got you beat Derek, well age wise not in years of experience...Plus, I am pretty sure yoy could program circles around me. Anyway, great video! Your videos are always clear, concise, and consistently of high quality. Anytime some one asks me anything along the lines of how do they get started programing i say go to your channel. Thx for all your awesome videos. keep it up :)
@derekbanas
@derekbanas 8 лет назад
Thank you for the very nice compliments :) Back in my day we saved code on cassette tapes, there were 3 books on programming at the library and Zork was my favorite game. I am so old.
@zacontraption
@zacontraption 8 лет назад
I only have Python 3.5, can I still use this tutorial for Python 6?
@derekbanas
@derekbanas 8 лет назад
Yes I'm using Python 3 here. The 6 is a reference that this is part 6 of the tutorial series
@trugate
@trugate 8 лет назад
whoa I know python 2 and 3, never heard of python 6! wait what year is it
@veganath
@veganath 7 лет назад
Bubble Sort - If the random list has the lowest value at the end then the sort will be incorrect. So it needs to be: while i>0 OR while i>=1
@s.m.asifmahfuz2101
@s.m.asifmahfuz2101 6 лет назад
I am a little confused about the nested for loops. what is the purpose of second for loop that contains j?
@derekbanas
@derekbanas 6 лет назад
You have to get values stored in both parts of the multidimensional array which requires changing the 1st and 2nd index
@s.m.asifmahfuz2101
@s.m.asifmahfuz2101 6 лет назад
thanks.
@shyamkumarbhattarai393
@shyamkumarbhattarai393 3 года назад
Derek Could you please make videos on network programming?
@derekbanas
@derekbanas 3 года назад
I’ll see what I can do
@rogeriosouza9288
@rogeriosouza9288 5 лет назад
My code was: multiply= [1,2,3,4,5,6,7,8,9] for i in range (9): myList = [[multiply[i]*j] for j in multiply] print(myList) is that incorrect?
@rohannaasha9811
@rohannaasha9811 6 лет назад
bro! please make videos on algorithms in python
@fr0iler578
@fr0iler578 8 лет назад
When will u make one on object oriented programming?
@derekbanas
@derekbanas 8 лет назад
Next is recursive functions, files and then oop. The OOP tutorial will probably be a multipart tutorial. I'll upload a new one every Wednesday and Saturday.
@sisyphus_619
@sisyphus_619 8 лет назад
How far is this course going to continue? :D
@derekbanas
@derekbanas 8 лет назад
Until I feel I've completely covered the topic. A complete coverage of Python and many problems from Project Euler should be expected.
@KamilTM1
@KamilTM1 8 лет назад
Which programming language You use mostly?:)
@derekbanas
@derekbanas 8 лет назад
JavaScript and PHP, but that is because I'm mainly a web designer that designs shopping carts
@shivapandey04
@shivapandey04 8 лет назад
It shoud be while i: or while i >= 1: or while i > 0 in bubble sort.
@paavangupta3420
@paavangupta3420 7 лет назад
in the part 21:59 the output is in float though you have not declared any float value there. Why is it like that
@derekbanas
@derekbanas 7 лет назад
You don't have to define types in Python
@larryogunbanjo4170
@larryogunbanjo4170 8 лет назад
Whats the difference between a bubble sort and the sort function?
@derekbanas
@derekbanas 8 лет назад
+Larry Ogunbanjo The sort function I believe uses quick sort, which is faster
@paavangupta3420
@paavangupta3420 7 лет назад
Sir, i am not able to create logic for programs how can i be able to do that and sometimes when you are writing the programs, i am getting confused​ in that also, just sometimes not everytime and sir really your way of teaching is very good thanks for your tutorials sir
@derekbanas
@derekbanas 7 лет назад
Thank you :) What do you mean by logic for programs?
@paavangupta3420
@paavangupta3420 7 лет назад
Sir, by logic i mean solutions like how can i do bubble sort without using the sort function (there may be a mathematical equation for that) so how can i do that. means like to print the prime numbers you designed a program so i was confused that how does it work you entered some mathematical equations. in that. Sir, should i be good in mathematics to be good at programming
@endlessetudes2029
@endlessetudes2029 7 лет назад
Hey Pavaan. I've seen your posts in this playlist a couple of times. The best advice I can give is to practice very simple problems. 1. Take notes on any new function in a lesson like .isdigit(), or .count() and try to use them on your own. 2. Next, try to use that function in a loop. Any kind of loop and print() every variable in every step. (Printing out variables and iterations helped me out a lot when i started. I'm still a beginner, but I'm making progress.) Also, Derek moves quickly. If you don't fully understand what's happened, that's completely understandable. 3. Pause the video and click on his transcript link, in the description. Stare at the code and talk yourself through the steps in your own words. For instance what is 'i' during this loop? what number is it? what is it keeping track of? I, myself, didn't understand all of the pieces to the bubble sort, so I'm going to look through the transcript and work through it step by step before moving on. Good luck
@paavangupta3420
@paavangupta3420 7 лет назад
Thank you for helping me 👍
@LizardanNet
@LizardanNet 8 лет назад
I thought you needed to add "self" as the first argument in every function call. It's not needed anymore? if so, as of when?
@kingsleyatuba
@kingsleyatuba 8 лет назад
thanks again
@derekbanas
@derekbanas 8 лет назад
You're welcome :)
@paavangupta3420
@paavangupta3420 7 лет назад
[[0] * 10 for i in range(10)] Sir, how does that works plz reply Sir, can i ask you more doubts when i have them
@derekbanas
@derekbanas 7 лет назад
That is a shortcut for generating a 10 x 10 list. Yes feel free to ask questions
@amrojjeh
@amrojjeh 7 лет назад
I don't get multTable = [[0] * 10 for i in range(10)] line. Why does it create 10 0s inside 10 lists inside 1 list? Can someone break it down for me?
@khaledmahmoud511
@khaledmahmoud511 7 лет назад
its like this in every row multiply a column witch has a value of 0 10 times which means creates a 10 column in every row with the value of zero u see he is not multiplying the zero itself he is creating a 10 small lists inside a bigger list which u can call a row thats how i understand it maybe im wrong or my explanation is some what complex .
@amrojjeh
@amrojjeh 7 лет назад
A bit late...but alright! I just need to remember what I was asking about and then I will read your answer!
@sideman6428
@sideman6428 7 лет назад
its bothering me too and no matter how many times i rewatch the video i still dont get it
@NielsvanWijnen
@NielsvanWijnen 6 лет назад
if i understand it correctly, then derek has generated the following 10x10 multitable at the end of this tutorial: you just don't see all the zero's because he adjusted and printed from [1,1] and up, instead of [0,0] and up. So it looks like a 9x9. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 0, 9, 18, 27, 36, 45, 54, 63, 72, 81, if you truly want to make the 9x9 table, then i think the code below might also work. Notice that in this case it will start in the [0,0] 'which derek showed in previous example is the very first box in the top left corner' and it wil put the number (0+1)*(0+1) = 1. which is exactly what we want for our first number. Hope i make sense and explained it correctly. multiDlijst = [[0]*9 for i in range(9)] for i in range(9): for j in range(9): multiDlijst[i][j] = (i+1)*(j+1) print(multiDlijst[i][j], end = ", ") print()
@MrSarky1992
@MrSarky1992 6 лет назад
Hi Niels, This is what was bothering me that he had extra 0s. What I ended up doing, very similarly to yours: listOfValues = [[] for i in range(9)] for i in range(9): listOfValues[i] = [(i+1)*j for j in range(1,10)] Then you can print out or w.e.
@sideman6428
@sideman6428 7 лет назад
25:53 doesn't [0] * 4 mean a list with 4 zeros like [0,0,0,0] ?
Далее
Learn to Program 7 : Recursive Functions Dictionaries
21:25
Learn to Program 10 : Inheritance Magic Methods
30:52
Купил КЛОУНА на DEEP WEB !
35:51
Просмотров 3,2 млн
10 Python Comprehensions You SHOULD Be Using
21:35
Просмотров 153 тыс.
Learn to Program 5 : Functions
29:00
Просмотров 55 тыс.
Premature Optimization
12:39
Просмотров 826 тыс.
Learn to Program 9 : Object Oriented Programming
30:05
Debugging 101: Replace print() with icecream ic()
12:36
Python lists, sets, and tuples explained 🍍
15:06
Просмотров 295 тыс.
Learn to Program 4 : String Functions
29:11
Просмотров 59 тыс.