In [2]:
inner=["cat", "dog", "bear"]
In [3]:
otherinner = [1, 2, 3]
In [4]:
mylist = [inner,otherinner]
In [5]:
mylist
Out[5]:
In [6]:
nested = [["a", 1, "b"], ["dog"]]
In [7]:
print(nested)
In [9]:
print(list(range(5)))
In [12]:
dummy_input = """5
Harry
37.21
Berry
37.21
Tina
37.2
Akriti
41
Harsh
39"""
In [33]:
numbers = []
names = []
for x in dummy_input.split("\n")[1:]:
try:
fl = float(x)
numbers.append(fl)
except:
names.append(x)
print(numbers)
print(names)
In [34]:
print(list(zip(names, numbers)))
In [35]:
def get_students(instring):
listofstrings = instring.split("\n")[1:]
names = []
numbers = []
for x in listofstrings:
try:
fl = float(x)
numbers.append(fl)
except:
names.append(x)
index_cards = list(zip(names, numbers))
grades = []
for x in index_cards:
grades.append(x[1])
grades = list(set(grades))
grades = sorted(grades)
secondlowest = grades[1]
almost_flunking = []
for student in index_cards:
if student[1] == secondlowest:
almost_flunking.append(student[0])
for x in sorted(almost_flunking):
print(x)
In [36]:
get_students(dummy_input)
In [40]:
"angrycat"[5:]
Out[40]:
In [ ]: