Python Programming Tutorial – 13 – Slicing Lists
Part 14 – www.youtube.com How to slice lists
May 5, 2010 | Filed Under Python Tutorials
Comments
25 Responses to “Python Programming Tutorial – 13 – Slicing Lists”
Powered by Yahoo! Answers
lol
I wana get a shirt that says Buck is my home boy…
Print (‘Bucky is my home boy!’)
[m:n] can be read as starting from m, up to n (but not including n)
Great tutorial
del example[1:4]
works too
Totally AGREE!!!
I’m a bit confused, didn’t we learn slicing in tutorial 10?
It’s just giving u an examples of more complicated stuff.
Okay. So…
Using list slicing (or regular slicing), could one make a game in which you have titles (like Warrior, Hacker, Hunter, and so forth) – and each time you level up (or something), that title change? That is, if combined with if statements (I guess)?
Something like that.
yea i think it would b cool to make like a MUD python game…like a text based RPG…is anybody has skype we could get together and make it…anybody got a skype?
im precisely trying to do that but.. cant find a thing..
I wanna do like a 2 option game but how can I make the options? it would be cool if I could do something like:
print “A woman comes up to you and says: Hello. You are here.”
print “Do you want to speak to her?”
if “yes” = true print “What do you want to know?”
if “no” = true print “Bye.”
endif
Whats wrong there?
Well i can help you with that…just do this…
Print”A woman comes up to you and says : ‘HELLO’ ”
print “do you want to speak to her? (yes or no)”
c = input()
if c == ‘yes’ or ‘YES’:
print”What do you want to know?”
if c == ‘no’ or ‘NO’:
print “Bye”
for example if i give them an option to go through a door or talk to somebody.. they choose to talk to someone and i want to bring thm bck to the original Q..how do i do thatwithout rewriting tons,seroiusly is ther like a goto stmnt?
1xxxbenxxx1 i think you must put a WHILE
and i dont know…something who change the variable in the while, and that get you out or into it….
i mean
humm…is a bit long to write it in here…..anyway i hope you understand me ^^ cya!!!
print “A woman comes up to you and says: Hello. You are here.”
speaktohoe = raw_input (“Do you want to speak to her? “)
if speaktohoe == “yes” or “Yes”:
print “What do you want to know?”
if speaktohoe == “no” or “No”:
print “Bye”
gtfo = raw_input (“Leave.”)
it is nice..i did something like that about 6 years ago when i tried programming for the first time. I suppose that whole game would be a large tree, but that is hardly maintainable…maybe you should try something like neuron networks or similar practiques before starting a project. good luck and have fun :-)
it basically is:
print “Hello!”
option = raw_input(“Prompt type yes to play a game or no to quit: “)
if (option == “yes”):
print “Welcome”
else:
print “Bye”
I can do it with you but at first I need to know what is MUD game =))
It’s a text based RPG…google it bro! :D
LOL
Thank you very much.
yeah Buck – strong work my friend.
For the speaktohoe variable use the “.lower()” or the “.upper()” method to make the response into lowercase because what if the user inputs “yes” or “no” in upper case?
what could i put as an element in a list to make it change to a random letter/number?
EX::
example=list(‘putwhateverhere”)
example[4]= <–what would i put there to make it a random change? i want it to take the specified element and change it to a random number/letter…. help??
what if i want to add a list after the last element in the list… I tried name[-1:-1]={‘x’] but it gets added before the last character but i want to add after the last character.
@picknpac i didn’t really tried to use the [] but i tried to use + for this case… idk if there’s another way…
so instead of name[-1:-1]=[x], I did name = name + list[x]
I can’t wait to finish the tuts. Start working on projects like Frets on Fire :D