Avatar of jameskane
jameskane

asked on 

Python 3.4 List manipulation

Hi, I have a list which contains  unique and identical sub lists randomly dispersed across the list . There is no limit on the number of identical sub lists which may exist, and they are not necessarily clustered together.

All sub lists have 1 as their first element - which acts as a counter. So, if there are, 3 identical sub lists [1,9,12] - these three sub lists  would be  replaced by a single sub list [3,9,12]

example

MYLIST = [ [1,9,12], [1, 6, 12],  [1, 5, 5],  [1, 8, 32],  [1, 5, 5],  [1,9,12],  [1,9,12] ]  

MYLIST_Converted =  [[3,9,12], [1, 6, 12],  [2, 5, 5], [1, 8, 32]]

Can someone give me a sense of how best to approach this. Been trying for a couple of days without success.

Thanks.
Python

Avatar of undefined
Last Comment
kaufmed
Avatar of kaufmed
kaufmed
Flag of United States of America image

Is this school work?
Avatar of jameskane
jameskane

ASKER

Its hobby work for  an old retired guy !!   Promise !

I'm trying to convert an old Coldfusion application I did for the local art school.
Avatar of jameskane
jameskane

ASKER

kaufmed, see   cannes-beaux-arts.com  ... see right hand side, middle for my name on site for art school
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of jameskane
jameskane

ASKER

INGENIOUS !!!!
works perfectly.
Went through code and learned a lot - thanks for that also.

The only   bit I am struggling to understand are the last two lines

if __name__ == '__main__':
    main()

If you have a minute, could you send me a few words / pointer of explanation ?

Many thanks
Avatar of aikimark
aikimark
Flag of United States of America image

you don't need to package your code this way.  You can put all of the main function code into your module as is.
Avatar of kaufmed
kaufmed
Flag of United States of America image

Python
Python

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.

6K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo