A tiny bit more Python
A tiny bit more Python
Ruth Anderson UW CSE 160 Autumn 2021
1
See in python tutor
Enumerate a list
lst = [10 ** x for x in range(10)]
for i in range(len(lst)): print('value at index', i, 'is', lst[i])
index
value
Or:
for index, value in enumerate(lst): print('value at index', index, 'is', value)
Like dict.items()
2
Enumerate a list
Goal: add each element's index itself
lst = [x for x in range(10)] new_lst = [] for i, v in enumerate(lst):
new_lst.append(i + v)
With a list comprehension:
lst = [x for x in range(10)] new_lst = [i + v for i, v in enumerate(lst)]
3
See in python tutor
Activity: Enumerate a list
Goal: Given a list of participants, in the order they finished a race, create a dictionary that maps their name to their finishing place.
Racers
racers = ['Dino', 'Wilma', 'Barney', 'Fred'] race_dict = {'Dino':1, 'Wilma':2, 'Barney':3, 'Fred':4}
With a list comprehension:
race_dict =
4
See in python tutor
Activity: Enumerate a list
Goal: Given a list of participants, in the order they finished a race, create a dictionary that maps their name to their finishing place.
Racers
racers = ['Dino', 'Wilma', 'Barney', 'Fred'] race_dict = {'Dino':1, 'Wilma':2, 'Barney':3, 'Fred':4}
With a list comprehension:
race_dict = {v: i + 1 for i, v in enumerate(racers)}
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- python tutorial stanford computer vision lab
- working with lists and dictionaries ncert
- python tutorial list and negative indexing
- on to python
- python lists
- python programming 2 regular expressions lists
- cse 142 python slides university of texas at austin
- python day 3 lists branching iwks
- a tiny bit more python
- cs177 python programming purdue university
Related searches
- quite a bit synonym
- a more perfect union
- more importantly in a sentence
- python 32 bit download windows
- download python 32 bit windows
- download python 32 bit for windows 10
- more words for a thing
- a word for more and more
- is this a 64 bit computer
- tiny hands for tiny hands
- python 32 bit windows 10
- python 3 8 5 64 bit download