Skip to content

Commit ba34d77

Browse files
fix merge
Merge branch 'master' of https://github.com/RockefellerUniversity/Intro_To_Python # Conflicts: # docs/exercises/answers/Exercise1_answers.html # docs/exercises/answers/Exercise2_answers.html # docs/exercises/answers/Exercise3_answers.html # docs/exercises/exercises/Exercise1_exercise.html # docs/exercises/exercises/Exercise2_exercise.html # docs/exercises/exercises/Exercise3_exercise.html # r_course/exercises/answers/Exercise1_answers.html # r_course/exercises/answers/Exercise2_answers.html # r_course/exercises/answers/Exercise3_answers.html # r_course/exercises/exercises/Exercise1_exercise.html # r_course/exercises/exercises/Exercise2_exercise.html # r_course/exercises/exercises/Exercise3_exercise.html
2 parents 58e215b + e3ca938 commit ba34d77

51 files changed

Lines changed: 9301 additions & 1302 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

IntroToPython/inst/doc/Exercise1.Rmd

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -243,137 +243,3 @@ print(concatenate_1 + concatenate_2)
243243
244244
```
245245

246-
**Exercise 5** - **Lists**
247-
248-
- Create a list containing the values 1,2,3,4,5.
249-
250-
```{python,echo=toMessage}
251-
[1,2,3,4,5]
252-
253-
```
254-
- Create a list containing the values a,b,c,d,e, but assign it to a new variable called `x`.
255-
256-
```{python,echo=toMessage}
257-
x = ["a","b","c","d","e"]
258-
x
259-
```
260-
261-
- Create a list containing the values a,b,c, repeated 5 times and assign it to a new variable
262-
263-
```{python,echo=toMessage}
264-
y = ["a","b","c"] * 5
265-
y
266-
```
267-
268-
- Create a sublist with indexing. Use the variable you just created and extract the the 10th through to 15th position.
269-
270-
```{python, echo=toMessage}
271-
y[9:14]
272-
```
273-
274-
- With the same variable, let's use "-" indexing to get the last value of our list.
275-
276-
```{python, echo=toMessage}
277-
278-
y[-1]
279-
280-
281-
```
282-
283-
- Now print the values from [0:-1]
284-
285-
```{python, echo=toMessage}
286-
287-
y[0:-1]
288-
289-
290-
```
291-
292-
- Notice how the last value of your list is missing, even though you access it with [-1]. That's because slicing is exclusive, while indexing is inclusive.
293-
294-
295-
- Append the list in variable x. Add the string z.
296-
```{python, echo=toMessage}
297-
x.append('z')
298-
x
299-
```
300-
301-
- Delete the 2nd through 6th entry of x.
302-
```{python, echo=toMessage}
303-
del(x[1:5])
304-
x
305-
```
306-
307-
- Lets go back to variable y. Sort it in reverse order.
308-
```{python, echo=toMessage}
309-
y.sort(reverse=True)
310-
y
311-
```
312-
313-
314-
- Multiply the y variable by 2.
315-
316-
```{python, echo=toMessage}
317-
318-
y * 2
319-
320-
321-
322-
```
323-
324-
325-
- Use the function .remove() to eliminate "a" from your list.
326-
327-
```{python, echo=toMessage}
328-
329-
y.remove("a")
330-
331-
print(y)
332-
333-
```
334-
335-
- Notice that .remove() eliminates only the first instance of your specified entry.
336-
337-
- Create a list of lists. Use the values 1,2,3,4,5, along with the lists x and y.
338-
339-
```{python, echo=toMessage}
340-
nested_list = [[1,2,3,4,5], x, y]
341-
nested_list
342-
```
343-
344-
- Take your previous list of lists and use indexing to find the third entry of your third list.
345-
346-
```{python, echo=toMessage}
347-
348-
nested_list[2][2]
349-
350-
```
351-
352-
**Exercise 6** - **Tuples**
353-
354-
- Create a tuple containing the values 1,2,3,4,5.
355-
356-
```{python,echo=toMessage}
357-
(1,2,3,4,5)
358-
359-
```
360-
361-
362-
- Coerce list in variable x into a tuple.
363-
364-
```{python,echo=toMessage}
365-
tuple(x)
366-
367-
```
368-
369-
370-
- Make a touple with your list of lists.
371-
- Print your results
372-
373-
```{python, echo=toMessage}
374-
375-
nested_list_tuple = tuple(nested_list)
376-
377-
print(nested_list_tuple)
378-
379-
```

0 commit comments

Comments
 (0)