程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] learning notes week11-1 list

編輯:Python

【PYTHON】 List elements in ascending order form an integer # list

Title Description

Enter a list , Each of these elements is 0~9 Integer between , Output an integer consisting of all elements of the list sorted in ascending order .

Input

Enter a list , Each of these elements is 0~9 Integer between .

Output

Output an integer consisting of all elements of the list sorted in ascending order .

The sample input

[5, 4, 7, 4, 1]

Sample output

14457

a=eval(input())
a.sort()
sum=0
for i in a:
sum=sum*10+i
print(sum)

problem B: 【PYTHON】 List subtraction # list

Title Description

Enter the second list , In the list 1 Middle list 2 Delete some elements in .

Input

Input list 1 And list 2.

Output

Output the processed list 1

The sample input

[1,2,3,1,4] [3,1,5,3,6]

Sample output

[2, 4]

a=eval(input())
b=eval(input())
c=[i for i in a if i not in b]
print(c)

【PYTHON】 Find the subscript of the largest element in the list # list

Title Description

Enter a list of integers , Find the subscript of the largest element in the integer list , If the maximum number of elements exceeds 1, Then please print out all subscripts .

Input

Numbers 1, Numbers 2, Numbers 3,...., Numbers n

Output

Subscript 1 Subscript 2 ... Subscript k

The sample input

3,2,3

Sample output

0 2

a=list(map(eval,input().split(",")))
b=max(a)
for i in range(0,len(a)):
if a[i] == b:
print(i)

【PYTHON】 Find the last one 250# list

Title Description

They don't want to talk to you , And threw a bunch of numbers at you …… And you have to find it in this string of numbers “250” This touching number on the big .

Input

Input the number of absolute values in a row that do not exceed 1000 The integer of .

Output

Output the last occurrence in one line “250” It's the number that they threw ( Count from 1 Start ). If not “250” The number of , Output is 0.

The sample input

888 666 123 -233 250 13 250 -222

Sample output

7

a=list(map(eval,input().split(" ")))
b=0
for i in range(0,len(a)):
if a[i] == 250:
b=i
if b==0:
print(b)
else:
print(b+1)

【PYTHON】 List element parity sort # list

Title Description

Enter a include 10 individual 100 A list that does not repeat any number within , This list , Use sort function sorted() Generate a new list , Odd numbers come first and even numbers come last in the new list , And the relative order between odd numbers remains the same , The relative order between even numbers also remains the same .

Input

list

Output

Sorted list

The sample input

[2,6,45,9,34,10,91,62,36,18]

Sample output

[45, 9, 91, 2, 6, 34, 10, 62, 36, 18]

temp=eval(input())
a=[]
b=[]
for i in temp:
if i%2==1:
a.append(i)
else:
b.append(i)
print(a+b)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved