Python---element classification __python

Source: Internet
Author: User

Element classification

There are the following sets, [11,23,76,32,8,3,10,22,89,123,44]

LI=[11,23,76,32,8,3,10,22,89,123,44]

dic={' K1 ': [], ' K2 ': []}

For item in Li:

If Item >50:

If ' K2 ' in Dic.keys ():

dic[' K2 '].append (item)

Else

dic[' K2 ']=[item,] #创建只有一个元素的列表;

Else

If DiC ...

————————————————————

obj = file (' log ', ' R ')

Line_list=obj.readlines ()

Obj.close ()

Print Line_list

# can get [' lary|boy|22\n ', ' henry|boy|32\n ', ' jack|gail|12\n '] \ n for newline characters, list

Next, work on this list and put it in the required format

For Ele in Line_list:

Ele = Ele.strip () # Remove the spaces and line breaks lary|boy|22

ele_list= ele.split (' | ') # at this time ["Lary", "Boy", "22"]

Dic[ele_list[0]] = ele_list[1:]

Print dic


Log file Contents:

ary |boy|22

Henry|boy|32

Jack |girl|12.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.