-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_app.py
More file actions
56 lines (52 loc) · 1.33 KB
/
list_app.py
File metadata and controls
56 lines (52 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#list_type.py
#self prc:how to translate 2D array into 1D regular array
#for eg:
#input :['jay', 'is', 'handsome', ['curry', 'is', 'nba', 'basketball', 'player'], ['hello', 'python'], ['I', 'like', 'to', 'play', 'basketball']]
#output:['jay', 'is', 'handsome', ['hello', 'python'], 'curry', 'is', 'nba', 'basketball', 'player', 'I', 'like', 'to', 'play', 'basketball']
#preprocess
list1=["jay","is","handsome"]
list2=["curry","is","nba","basketball","player"]
list3=["hello","python"]
list4=["I","like","to","play","basketball"]
print(list1)
print(list2)
print(list3)
print(list4)
list1.append(list2)#list2 was not changed
list1.append(list3)
list1.append(list4)
print(list1)
#meth 1:
#by splitting the inner list , then extend the inner list into the main list
"""
#wrong ans
cnt=0
for i in list1:
if type(i) is type(list2):
print(cnt)
print(i)
list_tmp=i
list1.remove(i)
print(list1)
list1.extend(i)
print(list1)
cnt+=1
#ans:
print(list1)
"""
#wrong ans
cnt=0
for i in list1:
if type(i) is type(list2):
print(cnt)
print(i)
list_tmp=i
list1.remove(i)
print(list1)
for j in i:
list1.insert(cnt,j)
print(list1)
cnt+=1
#ans:
print("the final ans is:")
print(list1)