Select to view content in your preferred language

# ArcPY Python List

542
2
05-24-2018 01:19 PM
New Contributor III
I have a problem codding. I wonder if you could give me a hand with this:
I have this list of tuples:

[['060710080013011', 9, 155], ['060710080013011', 9, 156], ['060710080013011', 9, 157], ['060710080013011', 9, 164], ['060710080013011', 9, 165], ['060710080013011', 9, 166], ['060710080013011', 9, 170], ['060710080013011', 9, 171], ['060710080013011', 9, 172], ['060710080013033', 8, 86], ['060710080013033', 8, 90], ['060710080013033', 8, 91], ['060710080013033', 8, 97], ['060710080013033', 8, 99], ['060710080013033', 8, 100], ['060710080013033', 8, 103], ['060710080013033', 8, 105], ['060710080021000', 10, 87], ['060710080021000', 10, 88], ['060710080021000', 10, 89], ['060710080021000', 10, 92], ['060710080021000', 10, 93], ['060710080021000', 10, 94], ['060710080021000', 10, 95], ['060710080021000', 10, 96], ['060710080021000', 10, 98], ['060710080021000', 10, 102]]

So the first value is an ID y the second value is how many times this id is appearing on the list. The problem is the following.

When the second value is greater than 7, I need to change the values in every second item in each tuple here the example:

[['060710080013011', 7, 155], ['060710080013011', 7, 156], ['060710080013011', 7, 157], ['060710080013011', 7, 164], ['060710080013011', 7, 165], ['060710080013011', 7, 166], ['060710080013011', 7, 170], ['060710080013011_2', 2, 171], ['060710080013011_2', 2, 172]]

As you can see, instead of having 9 in all the values, I have 7 and 2, and I have to change the id of the left 2 adding a '_2' at the end. Basically, the rule is, id the value is greater than 7, then divide the value by 7. and put the residual in the rest of values. It could be the case that a value has 15 appearances. In that case, we will have 2 groups of 7 and one of 1

Please, I have been trying to solve this a lot of time, I can not find a solution.

Tags (3)
2 Replies
MVP Esteemed Contributor

Just an FYI, what you presented in the question is a list of lists, not a list of tuples.  Maybe your code is different than what you showed here, but I doubt you are using tuples since they are immutable and you would be getting errors trying to update values in them.

Before suggesting a solution, what would happen in your 15 appearances example?  You state there would be 2 groups of 7, what would the ID sequence look like after it is modified?

by
Regular Contributor II

If your question is about getting lost within Lists of Lists and how to reference particular elements within python... maybe this would help python - Access item in a list of lists - Stack Overflow   Again as Joshua indicated we are only guessing at what you need?