CSC 127A Lecture 20: CSC 127A/110 Week 7 10.7.16

47 views4 pages

Document Summary

For example, if you have [11, 42, -5, 27, 0, 89] but you would rather have this instead [89, 0, 27, -5, 42, 11: this list is numbered 0, 1, 2, 3, 4, 5. Week 7, 10/7/16: -6, -5,-4, -3, -2, -1 def main(): list = [11, 42, -5, 27, 0, 89] # this will still work with odds for i in range(0, len(list) // 2): temp = list[i] list[i] = list[-i -1] list[-i -1] = temp print(list) Below will not work because after it gets halfway, it just swaps them back into the same position for i in range(0, len(list)): temp = list[i] list[i] = list[-i -1] list[-i -1] = temp print(list) main() Make sure that your code returns, otherwise the function will not swap. Value semantics: behavior where values are copied when changed ints, floats, strings and booleans in python are value semantics.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions